@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.
Files changed (69) hide show
  1. package/README.md +169 -2
  2. package/dist/__tests__/parser.test.d.ts +1 -0
  3. package/dist/__tests__/pdf.spec.d.ts +1 -0
  4. package/dist/__tests__/region.test.d.ts +1 -0
  5. package/dist/__tests__/setupJest.d.ts +0 -0
  6. package/dist/assets/optimization.worker-C8u4PFfM.js +886 -0
  7. package/dist/assets/optimization.worker-C8u4PFfM.js.map +1 -0
  8. package/dist/convert.d.ts +223 -0
  9. package/dist/download.d.ts +115 -0
  10. package/dist/iiif.d.ts +110 -0
  11. package/dist/index.cjs +65 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.mjs +11137 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/io.d.ts +75 -0
  17. package/dist/log.d.ts +21 -0
  18. package/dist/metrics.d.ts +10 -0
  19. package/dist/ocr.d.ts +36 -0
  20. package/dist/optimization.d.ts +48 -0
  21. package/dist/optimization.worker.d.ts +1 -0
  22. package/dist/pdf/annos-text.d.ts +19 -0
  23. package/dist/pdf/annos.d.ts +4 -0
  24. package/dist/pdf/common.d.ts +48 -0
  25. package/dist/pdf/generator.d.ts +197 -0
  26. package/dist/pdf/image.d.ts +34 -0
  27. package/dist/pdf/parser.d.ts +131 -0
  28. package/dist/pdf/pkzip.d.ts +23 -0
  29. package/dist/pdf/png.d.ts +34 -0
  30. package/dist/pdf/util.d.ts +18 -0
  31. package/dist/res/licenses.d.ts +7 -0
  32. package/dist/res/srgbColorspace.d.ts +2 -0
  33. package/dist/util.d.ts +8 -0
  34. package/dist/version.d.ts +2 -0
  35. package/package.json +149 -4
  36. package/src/__tests__/fixtures/deep_toc.json +2953 -0
  37. package/src/__tests__/fixtures/flat_toc.json +2917 -0
  38. package/src/__tests__/fixtures/physdim.json +294 -0
  39. package/src/__tests__/fixtures/region_target.json +58 -0
  40. package/src/__tests__/fixtures/wunder.jpg +0 -0
  41. package/src/__tests__/parser.test.ts +42 -0
  42. package/src/__tests__/pdf.spec.ts +216 -0
  43. package/src/__tests__/region.test.ts +194 -0
  44. package/src/__tests__/setupJest.ts +2 -0
  45. package/src/convert.ts +1098 -0
  46. package/src/download.ts +703 -0
  47. package/src/global.d.ts +10 -0
  48. package/src/iiif.ts +605 -0
  49. package/src/index.ts +7 -0
  50. package/src/io.ts +243 -0
  51. package/src/log.ts +51 -0
  52. package/src/metrics.ts +47 -0
  53. package/src/ocr.ts +176 -0
  54. package/src/optimization.ts +201 -0
  55. package/src/optimization.worker.ts +118 -0
  56. package/src/pdf/annos-text.ts +382 -0
  57. package/src/pdf/annos.ts +240 -0
  58. package/src/pdf/common.ts +158 -0
  59. package/src/pdf/generator.ts +1665 -0
  60. package/src/pdf/image.ts +340 -0
  61. package/src/pdf/parser.ts +811 -0
  62. package/src/pdf/pkzip.ts +228 -0
  63. package/src/pdf/png.ts +397 -0
  64. package/src/pdf/util.ts +111 -0
  65. package/src/res/licenses.ts +266 -0
  66. package/src/res/srgbColorspace.ts +405 -0
  67. package/src/types.d.ts +6 -0
  68. package/src/util.ts +55 -0
  69. package/src/version.ts +1 -0
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # pdiiif-lib
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ## Sample Usage
4
+
5
+ The example code below will generate a PDF in the browser, using the
6
+ public cover page API hosted at https://pdiiif.jbaiter.de and print
7
+ the progress to the console.
8
+
9
+ ```javascript
10
+ import { convertManifest, estimatePdfSize } from 'pdiiif-lib';
11
+
12
+ // Fetch the manifest
13
+ const manifestUrl = 'https://iiif.wellcomecollection.org/presentation/v2/b18035723';
14
+ const manifestResp = await fetch(manifestUrl);
15
+ const manifest = await manifestResp.json();
16
+
17
+ // Estimate how large a PDF will probably be given the parameters
18
+ const estimatedSizeInBytes = await estimatePdfSize({
19
+ manifestJson: manifest,
20
+ });
21
+
22
+ // Get a writable handle to a file on the user's machine
23
+ const handle = await showSaveFilePicker({
24
+ suggestedName: 'manifest.pdf',
25
+ types: [
26
+ {
27
+ description: 'PDF file',
28
+ accept: { 'application/pdf': ['.pdf'] },
29
+ }],
30
+ });
31
+ if ((await handle.queryPermission({ mode: 'readwrite' })) !== 'granted') {
32
+ console.error(`no permission to write to '${handle.name}'`);
33
+ } else {
34
+ pdfPath = (await handle.getFile()).name;
35
+ const webWritable = await handle.createWritable();
36
+
37
+ // Start the PDF generation
38
+ const onProgress = status => {
39
+ console.log(`Wrote ${status.pagesWritten} of ${totalPages}.`);
40
+ }
41
+ await convertManifest(
42
+ manifest,
43
+ webWritable,
44
+ {
45
+ onProgress,
46
+ coverPageEndpoint: 'https://pdiiif.jbaiter.de/api/coverpage'
47
+ }
48
+ )
49
+ };
50
+
51
+ ```
52
+
53
+ ## API
54
+
55
+ **convertManifest**: The main function of the libary, convert a manifest to a PDF and write it to a writable stream.
56
+
57
+ ```typescript
58
+ convertManifest(
59
+ manifest: ManifestV3 | ManifestV2 | string, // string is a URL to a manifest
60
+ writable: Writable /* NodeJS */ | WritableStream /* Browsers */,
61
+ {
62
+ /// Callback to provide annotations for a given canvas identifier.
63
+ /// Should return either a `sc:AnnotationList` (IIIF2) or an `AnnotationPage` (IIIF3).
64
+ /// Use this if you want to supply your own annotations for a third party manifest.
65
+ fetchCanvasAnnotations?: (
66
+ canvasId: string
67
+ ) => Promise<Array<IIIF3Annotation> | Array<Presentation2.Annotation>>;
68
+
69
+ /// Pixels per inch to assume for the full resolution version of each canvas.
70
+ /// If not set, the conversion will use an available IIIF Physical Dimensions
71
+ /// service to calculate the page dimensions instead or assume 300 ppi otherwise.
72
+ ppi?: number;
73
+
74
+ /// Set of canvas ids to include in PDF, or a predicate to filter canvas identifiers
75
+ //? by. By default, all canvases are included in the PDF.
76
+ filterCanvases?: readonly string[] | ((canvasId: string) => boolean);
77
+
78
+ /// List of languages to use for metadata, page labels and table of contents, in
79
+ /// descending order of preference. Will use the environment's locale settings by
80
+ /// default.
81
+ languagePreference?: readonly string[];
82
+
83
+ /// Restrict the image size to include in the PDF by downscaling by a fixed factor.
84
+ /// The value must be a number between 0.1 and 1.
85
+ /// Only works with Level 2 Image API services that allow arbitrary downscaling, the
86
+ /// conversion will not perform downscaling itself.
87
+ /// For Level 1 endpoints, the closest available lower width will be selected.
88
+ scaleFactor?: number;
89
+
90
+ /// Number of maximum concurrent IIIF Image API requests to be performed, defaults to 1
91
+ /// NOTE: Be nice, increasing this nubmer will speed up the PDF generation, but also
92
+ // put increased load on the IIIF provider's IIIF Image API server.
93
+ concurrency?: number;
94
+
95
+ /// Callback that gets called whenever a page has finished, useful to render a
96
+ /// progress bar.
97
+ onProgress?: (status: ProgressStatus) => void;
98
+
99
+ /// Controller that allows aborting the PDF generation. All pending downloads will be
100
+ /// terminated. The caller is responsible for removing underlying partial files and
101
+ /// user signaling.
102
+ abortController?: AbortController;
103
+
104
+ /// Set PDF metadata, by default `Title` will be the manifest's label.
105
+ metadata?: {
106
+ CreationDate?: Date;
107
+ Title?: string;
108
+ Author?: string;
109
+ Keywords?: string;
110
+ };
111
+
112
+ /// Endpoint to contact for retrieving PDF data with one or more cover pages
113
+ /// to insert before the canvas pages. The endpoint must accept a JSON payload
114
+ /// described in the `CoverPageParams` type (linked below) and return a PDF with
115
+ // one or more cover pages.
116
+ coverPageEndpoint?: string;
117
+
118
+ /// Callback to call for retrieving PDF data with one or more cover pages
119
+ /// to insert before the canvas pages.
120
+ /// The `CoverPageParams` type is described at
121
+ /// https://github.com/jbaiter/pdiiif/blob/main/pdiiif-lib/src/convert.ts#L74-L98
122
+ coverPageCallback?: (params: CoverPageParams) => Promise<Uint8Array>;
123
+
124
+ /// Generate the PDF in a way that the resulting file is also a valid
125
+ /// ZIP file that contains the manifest, all of the images and, if present,
126
+ /// the OCR files referenced in the manifest.
127
+ polyglotZipPdf?: boolean;
128
+
129
+ /// Base directory in the polyglot ZIP archive. If not set, all resource
130
+ /// directories will be top-level in the archive.
131
+ polyglotZipBaseDir?: string;
132
+
133
+ /// Render IIIF annotations as visible, selectable text on the page instead
134
+ /// of interactive PDF annotations. Defaults to false.
135
+ annotationsAsText?: boolean;
136
+
137
+ /// Standard PDF font family used when annotationsAsText is enabled.
138
+ /// Supports Helvetica (default), Times-Roman, and Courier.
139
+ annotationFont?: 'Helvetica' | 'Times-Roman' | 'Courier';
140
+ })
141
+ ```
142
+
143
+ Visible annotation text preserves basic HTML formatting: bold, italic,
144
+ underline, text color, and paragraph/line breaks. Text is laid out within the
145
+ annotation's spatial target.
146
+
147
+ **estimatePdfSize**: Estimate how large the PDF will be based on the parameters
148
+ and sampling a few pages. Returns the estimated file size in bytes.
149
+
150
+ ```typescript
151
+ estimatePdfSize({
152
+ /// The manifest to determine the PDF size for
153
+ manifestJson: any;
154
+ /**
155
+ * Restrict the image size to include in the PDF by downscaling by a fixed factor.
156
+ * The value must be a number between 0.1 and 1.
157
+ * Only works with Level 2 Image API services that allow arbitrary downscaling, the
158
+ * conversion will not perform downscaling itself.
159
+ * For Level 1 endpoints, the closest available lower width will be selected.
160
+ */
161
+ scaleFactor?: number
162
+ /// Set of canvas ids to include in PDF, or a predicate to filter canvas identifiers
163
+ /// by. By default, all canvases are included in the PDF.
164
+ filterCanvases?: readonly string[] | ((canvasId: string) => boolean);
165
+ /// Number of canvses to sample for estimation, defaults to 8
166
+ numSamples?: number;
167
+ /// Number of concurrent IIIF Image API requests to be performed, defaults to 1
168
+ concurrency?: number;
169
+ }): number;
170
+ ```
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
File without changes