@aboutgeo/pdiiif 0.0.0-stage → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -2
- package/dist/__tests__/parser.test.d.ts +1 -0
- package/dist/__tests__/pdf.spec.d.ts +1 -0
- package/dist/__tests__/region.test.d.ts +1 -0
- package/dist/__tests__/setupJest.d.ts +0 -0
- package/dist/assets/optimization.worker-C8u4PFfM.js +886 -0
- package/dist/assets/optimization.worker-C8u4PFfM.js.map +1 -0
- package/dist/convert.d.ts +223 -0
- package/dist/download.d.ts +115 -0
- package/dist/iiif.d.ts +110 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +11137 -0
- package/dist/index.mjs.map +1 -0
- package/dist/io.d.ts +75 -0
- package/dist/log.d.ts +21 -0
- package/dist/metrics.d.ts +10 -0
- package/dist/ocr.d.ts +36 -0
- package/dist/optimization.d.ts +48 -0
- package/dist/optimization.worker.d.ts +1 -0
- package/dist/pdf/annos-text.d.ts +19 -0
- package/dist/pdf/annos.d.ts +4 -0
- package/dist/pdf/common.d.ts +48 -0
- package/dist/pdf/generator.d.ts +197 -0
- package/dist/pdf/image.d.ts +34 -0
- package/dist/pdf/parser.d.ts +131 -0
- package/dist/pdf/pkzip.d.ts +23 -0
- package/dist/pdf/png.d.ts +34 -0
- package/dist/pdf/util.d.ts +18 -0
- package/dist/res/licenses.d.ts +7 -0
- package/dist/res/srgbColorspace.d.ts +2 -0
- package/dist/util.d.ts +8 -0
- package/dist/version.d.ts +2 -0
- package/package.json +149 -4
- package/src/__tests__/fixtures/deep_toc.json +2953 -0
- package/src/__tests__/fixtures/flat_toc.json +2917 -0
- package/src/__tests__/fixtures/physdim.json +294 -0
- package/src/__tests__/fixtures/region_target.json +58 -0
- package/src/__tests__/fixtures/wunder.jpg +0 -0
- package/src/__tests__/parser.test.ts +42 -0
- package/src/__tests__/pdf.spec.ts +216 -0
- package/src/__tests__/region.test.ts +194 -0
- package/src/__tests__/setupJest.ts +2 -0
- package/src/convert.ts +1098 -0
- package/src/download.ts +703 -0
- package/src/global.d.ts +10 -0
- package/src/iiif.ts +605 -0
- package/src/index.ts +7 -0
- package/src/io.ts +243 -0
- package/src/log.ts +51 -0
- package/src/metrics.ts +47 -0
- package/src/ocr.ts +176 -0
- package/src/optimization.ts +201 -0
- package/src/optimization.worker.ts +118 -0
- package/src/pdf/annos-text.ts +382 -0
- package/src/pdf/annos.ts +240 -0
- package/src/pdf/common.ts +158 -0
- package/src/pdf/generator.ts +1665 -0
- package/src/pdf/image.ts +340 -0
- package/src/pdf/parser.ts +811 -0
- package/src/pdf/pkzip.ts +228 -0
- package/src/pdf/png.ts +397 -0
- package/src/pdf/util.ts +111 -0
- package/src/res/licenses.ts +266 -0
- package/src/res/srgbColorspace.ts +405 -0
- package/src/types.d.ts +6 -0
- package/src/util.ts +55 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": "http://iiif.io/api/presentation/2/context.json",
|
|
3
|
+
"@type": "sc:Manifest",
|
|
4
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/manifest",
|
|
5
|
+
"label": "Eggers, Hartwig: König Ludwig Feier 1886 - BSB Cod.icon. 180 ti",
|
|
6
|
+
"metadata": [
|
|
7
|
+
{
|
|
8
|
+
"label": [
|
|
9
|
+
{ "@language": "de", "@value": "Autor" },
|
|
10
|
+
{ "@language": "zh", "@value": "作者" },
|
|
11
|
+
{ "@language": "en", "@value": "Author" }
|
|
12
|
+
],
|
|
13
|
+
"value": "Eggers, Hartwig"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"label": [
|
|
17
|
+
{ "@language": "de", "@value": "Titel" },
|
|
18
|
+
{ "@language": "zh", "@value": "書名" },
|
|
19
|
+
{ "@language": "en", "@value": "Title" }
|
|
20
|
+
],
|
|
21
|
+
"value": "König Ludwig Feier 1886 - BSB Cod.icon. 180 ti"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"label": [
|
|
25
|
+
{ "@language": "de", "@value": "Von" },
|
|
26
|
+
{ "@language": "zh", "@value": "由" },
|
|
27
|
+
{ "@language": "en", "@value": "By" }
|
|
28
|
+
],
|
|
29
|
+
"value": "Hartwig Eggers"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"label": [
|
|
33
|
+
{ "@language": "de", "@value": "Entstehung" },
|
|
34
|
+
{ "@language": "zh", "@value": "生成" },
|
|
35
|
+
{ "@language": "en", "@value": "Creation" }
|
|
36
|
+
],
|
|
37
|
+
"value": "München, 1886"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"label": [
|
|
41
|
+
{ "@language": "de", "@value": "Umfang" },
|
|
42
|
+
{ "@language": "zh", "@value": "範疇" },
|
|
43
|
+
{ "@language": "en", "@value": "Extent" }
|
|
44
|
+
],
|
|
45
|
+
"value": "1 Bl. - Papier"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"label": [
|
|
49
|
+
{ "@language": "de", "@value": "Maße" },
|
|
50
|
+
{ "@language": "zh", "@value": "尺寸" },
|
|
51
|
+
{ "@language": "en", "@value": "Dimensions" }
|
|
52
|
+
],
|
|
53
|
+
"value": "74,5 x 102,00 cm"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"label": [
|
|
57
|
+
{ "@language": "de", "@value": "Sprache" },
|
|
58
|
+
{ "@language": "zh", "@value": "語言" },
|
|
59
|
+
{ "@language": "en", "@value": "Language" }
|
|
60
|
+
],
|
|
61
|
+
"value": [
|
|
62
|
+
{ "@language": "de", "@value": "Deutsch" },
|
|
63
|
+
{ "@language": "zh", "@value": "德语" },
|
|
64
|
+
{ "@language": "en", "@value": "German" }
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"label": [
|
|
69
|
+
{ "@language": "de", "@value": "Anmerkung" },
|
|
70
|
+
{ "@language": "zh", "@value": "說明" },
|
|
71
|
+
{ "@language": "en", "@value": "Note" }
|
|
72
|
+
],
|
|
73
|
+
"value": "Einzelblatt"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"label": [
|
|
77
|
+
{ "@language": "de", "@value": "Anmerkung" },
|
|
78
|
+
{ "@language": "zh", "@value": "說明" },
|
|
79
|
+
{ "@language": "en", "@value": "Note" }
|
|
80
|
+
],
|
|
81
|
+
"value": "ArchIcon"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"label": [
|
|
85
|
+
{ "@language": "de", "@value": "Anmerkung" },
|
|
86
|
+
{ "@language": "zh", "@value": "說明" },
|
|
87
|
+
{ "@language": "en", "@value": "Note" }
|
|
88
|
+
],
|
|
89
|
+
"value": "Kurzaufnahme einer Handschrift"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"label": [
|
|
93
|
+
{ "@language": "de", "@value": "Standort" },
|
|
94
|
+
{ "@language": "zh", "@value": "位置" },
|
|
95
|
+
{ "@language": "en", "@value": "Location" }
|
|
96
|
+
],
|
|
97
|
+
"value": "München, Bayerische Staatsbibliothek -- Cod.icon. 180 ti"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"label": [
|
|
101
|
+
{ "@language": "de", "@value": "Identifikator" },
|
|
102
|
+
{ "@language": "zh", "@value": "標識" },
|
|
103
|
+
{ "@language": "en", "@value": "Identifier" }
|
|
104
|
+
],
|
|
105
|
+
"value": "BSB-ID 12631486"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"label": [
|
|
109
|
+
{ "@language": "de", "@value": "Identifikator" },
|
|
110
|
+
{ "@language": "zh", "@value": "標識" },
|
|
111
|
+
{ "@language": "en", "@value": "Identifier" }
|
|
112
|
+
],
|
|
113
|
+
"value": "BV040667603"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"label": [
|
|
117
|
+
{ "@language": "de", "@value": "Identifikator" },
|
|
118
|
+
{ "@language": "zh", "@value": "標識" },
|
|
119
|
+
{ "@language": "en", "@value": "Identifier" }
|
|
120
|
+
],
|
|
121
|
+
"value": "OCLC 826592499"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"label": [
|
|
125
|
+
{ "@language": "de", "@value": "Identifikator" },
|
|
126
|
+
{ "@language": "zh", "@value": "標識" },
|
|
127
|
+
{ "@language": "en", "@value": "Identifier" }
|
|
128
|
+
],
|
|
129
|
+
"value": "BSB-Hss Cod.icon. 180 ti"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"label": [
|
|
133
|
+
{ "@language": "de", "@value": "Identifikator des digitalen Objekts" },
|
|
134
|
+
{ "@language": "zh", "@value": "數位物件標識" },
|
|
135
|
+
{ "@language": "en", "@value": "Digital Object Identifier" }
|
|
136
|
+
],
|
|
137
|
+
"value": "<a href='https://mdz-nbn-resolving.de/urn:nbn:de:bvb:12-bsb00079445-0'>urn:nbn:de:bvb:12-bsb00079445-0</a>"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"label": [
|
|
141
|
+
{ "@language": "de", "@value": "Objektkategorie" },
|
|
142
|
+
{ "@language": "zh", "@value": "物件類別" },
|
|
143
|
+
{ "@language": "en", "@value": "Object Type" }
|
|
144
|
+
],
|
|
145
|
+
"value": "Buch"
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
"navDate": "1886-01-01T00:00:00Z",
|
|
149
|
+
"license": "http://creativecommons.org/licenses/by-nc-sa/4.0/deed.de",
|
|
150
|
+
"attribution": "Bayerische Staatsbibliothek",
|
|
151
|
+
"seeAlso": [
|
|
152
|
+
{
|
|
153
|
+
"@id": "https://opacplus.bsb-muenchen.de/title/BV040667603",
|
|
154
|
+
"label": "OPAC",
|
|
155
|
+
"format": "text/html"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"@id": "https://opacplus.bsb-muenchen.de/title/BV040667603?format=marc",
|
|
159
|
+
"label": "MARCXML",
|
|
160
|
+
"format": "application/marcxml+xml",
|
|
161
|
+
"profile": "http://www.loc.gov/standards/marcxml/"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"@id": "https://opacplus.bsb-muenchen.de/title/BV040667603?format=rdf",
|
|
165
|
+
"label": "RDF",
|
|
166
|
+
"format": "application/rdf+xml",
|
|
167
|
+
"profile": "https://lod.b3kat.de/doc"
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"sequences": [
|
|
171
|
+
{
|
|
172
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/sequences/normal",
|
|
173
|
+
"@type": "sc:Sequence",
|
|
174
|
+
"canvases": [
|
|
175
|
+
{
|
|
176
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/canvas/1",
|
|
177
|
+
"@type": "sc:Canvas",
|
|
178
|
+
"label": "1r (0001)",
|
|
179
|
+
"service": {
|
|
180
|
+
"@context": "http://iiif.io/api/annex/services/physdim/1/context.json",
|
|
181
|
+
"physicalScale": 0.008466666666666666,
|
|
182
|
+
"physicalUnits": "cm",
|
|
183
|
+
"profile": "http://iiif.io/api/annex/services/physdim"
|
|
184
|
+
},
|
|
185
|
+
"images": [
|
|
186
|
+
{
|
|
187
|
+
"@type": "oa:Annotation",
|
|
188
|
+
"motivation": "sc:painting",
|
|
189
|
+
"resource": {
|
|
190
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/image/v2/bsb00079445_00001/full/full/0/default.jpg",
|
|
191
|
+
"@type": "dctypes:Image",
|
|
192
|
+
"service": {
|
|
193
|
+
"@context": "http://iiif.io/api/image/2/context.json",
|
|
194
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/image/v2/bsb00079445_00001",
|
|
195
|
+
"profile": "http://iiif.io/api/image/2/level2.json",
|
|
196
|
+
"protocol": "http://iiif.io/api/image"
|
|
197
|
+
},
|
|
198
|
+
"format": "image/jpeg",
|
|
199
|
+
"width": 12003,
|
|
200
|
+
"height": 8913
|
|
201
|
+
},
|
|
202
|
+
"on": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/canvas/1"
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
"width": 12003,
|
|
206
|
+
"height": 8913
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/canvas/2",
|
|
210
|
+
"@type": "sc:Canvas",
|
|
211
|
+
"label": "1v (0002)",
|
|
212
|
+
"service": {
|
|
213
|
+
"@context": "http://iiif.io/api/annex/services/physdim/1/context.json",
|
|
214
|
+
"physicalScale": 0.008466666666666666,
|
|
215
|
+
"physicalUnits": "cm",
|
|
216
|
+
"profile": "http://iiif.io/api/annex/services/physdim"
|
|
217
|
+
},
|
|
218
|
+
"images": [
|
|
219
|
+
{
|
|
220
|
+
"@type": "oa:Annotation",
|
|
221
|
+
"motivation": "sc:painting",
|
|
222
|
+
"resource": {
|
|
223
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/image/v2/bsb00079445_00002/full/full/0/default.jpg",
|
|
224
|
+
"@type": "dctypes:Image",
|
|
225
|
+
"service": {
|
|
226
|
+
"@context": "http://iiif.io/api/image/2/context.json",
|
|
227
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/image/v2/bsb00079445_00002",
|
|
228
|
+
"profile": "http://iiif.io/api/image/2/level2.json",
|
|
229
|
+
"protocol": "http://iiif.io/api/image"
|
|
230
|
+
},
|
|
231
|
+
"format": "image/jpeg",
|
|
232
|
+
"width": 12003,
|
|
233
|
+
"height": 9477
|
|
234
|
+
},
|
|
235
|
+
"on": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/canvas/2"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
"width": 12003,
|
|
239
|
+
"height": 9477
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
"structures": [
|
|
245
|
+
{
|
|
246
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/range/0",
|
|
247
|
+
"@type": "sc:Range",
|
|
248
|
+
"label": [
|
|
249
|
+
{ "@language": "de", "@value": "Inhaltsverzeichnis" },
|
|
250
|
+
{ "@language": "en", "@value": "Table of Contents" }
|
|
251
|
+
],
|
|
252
|
+
"ranges": [
|
|
253
|
+
"https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/range/1",
|
|
254
|
+
"https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/range/2"
|
|
255
|
+
],
|
|
256
|
+
"viewingHint": "top"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/range/1",
|
|
260
|
+
"@type": "sc:Range",
|
|
261
|
+
"label": {
|
|
262
|
+
"@language": "und-Latn",
|
|
263
|
+
"@value": "Situationsplan vom Königlichen Hofgarten in München"
|
|
264
|
+
},
|
|
265
|
+
"canvases": [
|
|
266
|
+
"https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/canvas/1"
|
|
267
|
+
]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/range/2",
|
|
271
|
+
"@type": "sc:Range",
|
|
272
|
+
"label": { "@language": "und-Latn", "@value": "Farbchart" },
|
|
273
|
+
"canvases": [
|
|
274
|
+
"https://api.digitale-sammlungen.de/iiif/presentation/v2/bsb00079445/canvas/2"
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
],
|
|
278
|
+
"viewingDirection": "left-to-right",
|
|
279
|
+
"thumbnail": {
|
|
280
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/image/v2/bsb00079445_00001/full/280,/0/default.jpg",
|
|
281
|
+
"service": {
|
|
282
|
+
"@context": "http://iiif.io/api/image/2/context.json",
|
|
283
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/image/v2/bsb00079445_00001",
|
|
284
|
+
"profile": "http://iiif.io/api/image/2/level2.json",
|
|
285
|
+
"protocol": "http://iiif.io/api/image"
|
|
286
|
+
},
|
|
287
|
+
"format": "image/jpeg"
|
|
288
|
+
},
|
|
289
|
+
"logo": {
|
|
290
|
+
"@id": "https://api.digitale-sammlungen.de/iiif/images/bsb_logo.png",
|
|
291
|
+
"format": "image/png"
|
|
292
|
+
},
|
|
293
|
+
"viewingHint": "paged"
|
|
294
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": "http://iiif.io/api/presentation/3/context.json",
|
|
3
|
+
"id": "http://localhost:5173/manifest/0001",
|
|
4
|
+
"type": "Manifest",
|
|
5
|
+
"label": { "en": ["Two images with targets"] },
|
|
6
|
+
"items": [
|
|
7
|
+
{
|
|
8
|
+
"id": "http://localhost:5173/manifest/0001/canvas/c1",
|
|
9
|
+
"type": "Canvas",
|
|
10
|
+
"width": 1041,
|
|
11
|
+
"height": 1634,
|
|
12
|
+
"items": [
|
|
13
|
+
{
|
|
14
|
+
"id": "http://localhost:5173/manifest/0001/canvas/c1/page/1",
|
|
15
|
+
"type": "AnnotationPage",
|
|
16
|
+
"items": [
|
|
17
|
+
{
|
|
18
|
+
"id": "http://localhost:5173/manifest/0001/canvas/c1/annotation/a1",
|
|
19
|
+
"type": "Annotation",
|
|
20
|
+
"motivation": "painting",
|
|
21
|
+
"body": {
|
|
22
|
+
"id": "https://example.org/iiif/1_1/full/full/0/default.jpg",
|
|
23
|
+
"type": "Image",
|
|
24
|
+
"height": 1634,
|
|
25
|
+
"width": 1041,
|
|
26
|
+
"format": "image/jpeg",
|
|
27
|
+
"service": [
|
|
28
|
+
{ "@id": "https://example.org/iiif/1_1", "@type": "ImageService2", "profile": "level0" }
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"target": "http://localhost:5173/manifest/0001/canvas/c1#xywh=8,1,575,903"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "http://localhost:5173/manifest/0001/canvas/c1/annotation/a2",
|
|
35
|
+
"type": "Annotation",
|
|
36
|
+
"motivation": "painting",
|
|
37
|
+
"body": {
|
|
38
|
+
"type": "SpecificResource",
|
|
39
|
+
"source": {
|
|
40
|
+
"id": "https://example.org/iiif/2_2/full/full/0/default.jpg",
|
|
41
|
+
"type": "Image",
|
|
42
|
+
"height": 1634,
|
|
43
|
+
"width": 1041,
|
|
44
|
+
"format": "image/jpeg",
|
|
45
|
+
"service": [
|
|
46
|
+
{ "@id": "https://example.org/iiif/2_2", "@type": "ImageService2", "profile": "level0" }
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"selector": { "type": "ImageApiSelector", "region": "224,156,369,1149" }
|
|
50
|
+
},
|
|
51
|
+
"target": "http://localhost:5173/manifest/0001/canvas/c1#xywh=587,226,448,1396"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { PdfValueParser } from '../pdf/parser';
|
|
2
|
+
import { textEncoder } from '../pdf/util';
|
|
3
|
+
import { PdfRef } from '../pdf/common';
|
|
4
|
+
|
|
5
|
+
const FIXTURES = {
|
|
6
|
+
dict: `
|
|
7
|
+
<<
|
|
8
|
+
/TrueBool true
|
|
9
|
+
/FalseBool false
|
|
10
|
+
/NullValue null
|
|
11
|
+
/Integer -20
|
|
12
|
+
/Real -13.137
|
|
13
|
+
/String (Hello World)
|
|
14
|
+
/HexString <1337DEADBEEF>
|
|
15
|
+
/Ref 13 0 R
|
|
16
|
+
/Array [1 (Foo) <C0FFEF>]
|
|
17
|
+
/Nested << /Hello (World) >>
|
|
18
|
+
>>`,
|
|
19
|
+
specialString: '(One (\\0433)\\)\\n\\r)',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('The PDF object value parser', () => {
|
|
23
|
+
it('should correctly parse a string literal with nested parentheses and escaped characters', () => {
|
|
24
|
+
const parser = new PdfValueParser(textEncoder.encode(FIXTURES.specialString));
|
|
25
|
+
expect(parser.read()).toEqual('One (#3))\n\r');
|
|
26
|
+
});
|
|
27
|
+
it('should correctly parse a dictionary with all types', () => {
|
|
28
|
+
const parser = new PdfValueParser(textEncoder.encode(FIXTURES.dict));
|
|
29
|
+
const value = parser.read();
|
|
30
|
+
expect(value).toMatchObject({
|
|
31
|
+
TrueBool: true,
|
|
32
|
+
FalseBool: false,
|
|
33
|
+
Integer: -20,
|
|
34
|
+
Real: -13.137,
|
|
35
|
+
String: 'Hello World',
|
|
36
|
+
HexString: new Uint8Array([0x13, 0x37, 0xde, 0xad, 0xbe, 0xef]),
|
|
37
|
+
Ref: new PdfRef(13),
|
|
38
|
+
Array: [1, 'Foo', new Uint8Array([0xc0, 0xff, 0xef])],
|
|
39
|
+
Nested: { Hello: 'World' },
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { PDFDocument } from 'pdf-lib';
|
|
2
|
+
import tmp from 'tmp';
|
|
3
|
+
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { makeRef, serialize } from '../pdf/common';
|
|
7
|
+
import { exportPdfText, htmlToAnnotationText } from '../pdf/annos-text';
|
|
8
|
+
import PDFGenerator from '../pdf/generator';
|
|
9
|
+
import { NodeWriter } from '../io';
|
|
10
|
+
import { Annotation } from '../iiif';
|
|
11
|
+
import { initializeSaxParser } from '../util';
|
|
12
|
+
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
initializeSaxParser(
|
|
15
|
+
fs.readFileSync(
|
|
16
|
+
path.resolve(__dirname, '../../node_modules/sax-wasm/lib/sax-wasm.wasm')
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('JavaScript->PDF value serialization', () => {
|
|
22
|
+
it('should convert Unicode strings with braces to UTF16BE', () => {
|
|
23
|
+
expect(serialize('(Hellö Wörld)')).toBe(
|
|
24
|
+
'<FEFF00480065006C006C00F60020005700F60072006C0064>'
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
it('should not convert ASCII strings', () => {
|
|
28
|
+
expect(serialize('(Hello World)')).toBe('(Hello World)');
|
|
29
|
+
});
|
|
30
|
+
it('should not convert strings without braces', () => {
|
|
31
|
+
expect(serialize('HelloWorld')).toBe('HelloWorld');
|
|
32
|
+
});
|
|
33
|
+
it('should convert Uint8Arrays to a hex string', () => {
|
|
34
|
+
expect(serialize(new Uint8Array([0, 16, 32, 64, 128, 256]))).toBe(
|
|
35
|
+
'<001020408000>'
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
it('should convert Dates to a PDF date string', () => {
|
|
39
|
+
expect(serialize(new Date('01 Jan 1970 00:00:00 GMT'))).toBe(
|
|
40
|
+
'(D:19700101000000Z)'
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
it('should convert objects to dictionaries', () => {
|
|
44
|
+
expect(serialize({ Foo: 'bar' })).toBe('<<\n /Foo bar\n>>');
|
|
45
|
+
});
|
|
46
|
+
it('should correctly encode PDF references', () => {
|
|
47
|
+
expect(serialize(makeRef(15))).toBe('15 0 R');
|
|
48
|
+
expect(serialize(makeRef({ num: 32 }))).toBe('32 0 R');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('PDF generation', () => {
|
|
53
|
+
it('uses standard-font page text instead of PDF annotations when requested', async () => {
|
|
54
|
+
const pdfPath = tmp.tmpNameSync({
|
|
55
|
+
prefix: 'pdiiif-test-',
|
|
56
|
+
postfix: '.pdf',
|
|
57
|
+
});
|
|
58
|
+
const writer = new NodeWriter(fs.createWriteStream(pdfPath));
|
|
59
|
+
const anno: Annotation = {
|
|
60
|
+
id: 'test-annotation',
|
|
61
|
+
markup: '<p>Visible <strong>text</strong></p>',
|
|
62
|
+
target: {
|
|
63
|
+
type: 'SpecificResource',
|
|
64
|
+
source: { id: 'canvas', type: 'Canvas' },
|
|
65
|
+
selector: {
|
|
66
|
+
type: 'BoxSelector',
|
|
67
|
+
spatial: { x: 10, y: 20, width: 200, height: 80 },
|
|
68
|
+
},
|
|
69
|
+
selectors: [],
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const pdfgen = new PDFGenerator({
|
|
73
|
+
writer,
|
|
74
|
+
metadata: {},
|
|
75
|
+
langPref: ['en'],
|
|
76
|
+
canvasInfos: [
|
|
77
|
+
{
|
|
78
|
+
canvas: { id: 'canvas', type: 'Canvas' },
|
|
79
|
+
images: [],
|
|
80
|
+
numAnnotations: 1,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
outline: [],
|
|
84
|
+
annotationsAsText: true,
|
|
85
|
+
annotationFont: 'Times-Roman',
|
|
86
|
+
});
|
|
87
|
+
await pdfgen.setup();
|
|
88
|
+
await pdfgen.renderPage(
|
|
89
|
+
'canvas',
|
|
90
|
+
{ width: 300, height: 200 },
|
|
91
|
+
[],
|
|
92
|
+
[anno],
|
|
93
|
+
undefined,
|
|
94
|
+
300
|
|
95
|
+
);
|
|
96
|
+
await pdfgen.end();
|
|
97
|
+
|
|
98
|
+
const pdfData = await fs.promises.readFile(pdfPath);
|
|
99
|
+
const parsed = await PDFDocument.load(pdfData.buffer.slice(0), {
|
|
100
|
+
throwOnInvalidObject: false,
|
|
101
|
+
});
|
|
102
|
+
expect(parsed.getPage(0).node.Annots()).toBeUndefined();
|
|
103
|
+
fs.unlinkSync(pdfPath);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('renders formatted annotation markup as visible page text', async () => {
|
|
107
|
+
const markup =
|
|
108
|
+
'<p>This <em>is</em> a <span style="color: rgb(204, 0, 0);">test</span> <strong>annotation</strong>. Café €</p>';
|
|
109
|
+
const runs = await htmlToAnnotationText(markup);
|
|
110
|
+
expect(runs.find((run) => run.text === 'is')).toMatchObject({
|
|
111
|
+
italic: true,
|
|
112
|
+
});
|
|
113
|
+
expect(runs.find((run) => run.text === 'test')).toMatchObject({
|
|
114
|
+
color: [0.8, 0, 0],
|
|
115
|
+
});
|
|
116
|
+
expect(runs.find((run) => run.text === 'annotation')).toMatchObject({
|
|
117
|
+
bold: true,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const anno: Annotation = {
|
|
121
|
+
id: 'test-annotation',
|
|
122
|
+
markup: `${markup}<p><u>underlined</u></p>`,
|
|
123
|
+
target: {
|
|
124
|
+
type: 'SpecificResource',
|
|
125
|
+
source: { id: 'canvas', type: 'Canvas' },
|
|
126
|
+
selector: {
|
|
127
|
+
type: 'BoxSelector',
|
|
128
|
+
spatial: { x: 10, y: 20, width: 200, height: 80 },
|
|
129
|
+
},
|
|
130
|
+
selectors: [],
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const ops = await exportPdfText(anno, 1, 200, 300, 'Times-Roman');
|
|
134
|
+
expect(ops.join('\n')).toContain('/annFontTimesRomanItalic 10 Tf');
|
|
135
|
+
expect(ops.join('\n')).toContain('/annFontTimesRomanBold 10 Tf');
|
|
136
|
+
expect(ops.join('\n')).toContain('0.8 0 0 rg');
|
|
137
|
+
expect(ops.join('\n')).toMatch(/RG 0\.5 w .* m .* l S Q/);
|
|
138
|
+
expect(ops.join('\n')).toContain('<54686973> Tj');
|
|
139
|
+
expect(ops.join('\n')).toContain('<436166e9> Tj');
|
|
140
|
+
expect(ops.join('\n')).toContain('<80> Tj');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should initialize a PDF with the correct metadata', async () => {
|
|
144
|
+
const pdfPath = tmp.tmpNameSync({
|
|
145
|
+
prefix: 'pdiiif-test-',
|
|
146
|
+
postfix: '.pdf',
|
|
147
|
+
});
|
|
148
|
+
const nodeStream = fs.createWriteStream(pdfPath);
|
|
149
|
+
const writer = new NodeWriter(nodeStream);
|
|
150
|
+
const metadata = {
|
|
151
|
+
Title: 'Täst Tütle',
|
|
152
|
+
};
|
|
153
|
+
const pdfgen = new PDFGenerator({
|
|
154
|
+
writer,
|
|
155
|
+
metadata,
|
|
156
|
+
langPref: ['en'],
|
|
157
|
+
canvasInfos: [
|
|
158
|
+
{
|
|
159
|
+
canvas: { id: 'foo', type: 'Canvas' },
|
|
160
|
+
images: [
|
|
161
|
+
{
|
|
162
|
+
resource: { id: 'foo', type: 'Image' },
|
|
163
|
+
x: 0,
|
|
164
|
+
y: 0,
|
|
165
|
+
width: 1024,
|
|
166
|
+
height: 1024
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
numAnnotations: 0,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
outline: [],
|
|
173
|
+
pageLabels: ['Tüst Läbel']
|
|
174
|
+
});
|
|
175
|
+
await pdfgen.setup();
|
|
176
|
+
const imgBuf = await fs.promises.readFile(
|
|
177
|
+
path.resolve(__dirname, './fixtures/wunder.jpg')
|
|
178
|
+
);
|
|
179
|
+
await pdfgen.renderPage(
|
|
180
|
+
'http://some.fixture',
|
|
181
|
+
{ width: 290, height: 400 },
|
|
182
|
+
[
|
|
183
|
+
{
|
|
184
|
+
resource: { id: 'someid', type: 'Image' },
|
|
185
|
+
width: 290, height: 400,
|
|
186
|
+
x: 0, y: 0,
|
|
187
|
+
data: imgBuf,
|
|
188
|
+
numBytes: imgBuf.length,
|
|
189
|
+
corsAvailable: true,
|
|
190
|
+
choiceInfo: {
|
|
191
|
+
enabled: true,
|
|
192
|
+
optional: false,
|
|
193
|
+
visibleByDefault: true
|
|
194
|
+
},
|
|
195
|
+
format: 'jpeg',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
[],
|
|
199
|
+
undefined,
|
|
200
|
+
72
|
|
201
|
+
);
|
|
202
|
+
await pdfgen.end();
|
|
203
|
+
|
|
204
|
+
const pdfData = await fs.promises.readFile(pdfPath);
|
|
205
|
+
const parsed = await PDFDocument.load(pdfData.buffer.slice(0), {
|
|
206
|
+
throwOnInvalidObject: false,
|
|
207
|
+
});
|
|
208
|
+
expect(parsed.getPageCount()).toBe(1);
|
|
209
|
+
expect(parsed.getPage(0).getSize()).toMatchObject({
|
|
210
|
+
width: 290,
|
|
211
|
+
height: 400,
|
|
212
|
+
});
|
|
213
|
+
expect(parsed.getTitle()).toEqual('Täst Tütle');
|
|
214
|
+
fs.unlinkSync(pdfPath);
|
|
215
|
+
});
|
|
216
|
+
});
|