pdfjs-serverless 0.1.0 → 0.2.0

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 (59) hide show
  1. package/README.md +11 -8
  2. package/dist/index.d.ts +1 -1
  3. package/dist/types/external/webL10n/l10n.d.ts +0 -0
  4. package/dist/types/src/display/annotation_layer.d.ts +203 -0
  5. package/dist/types/src/display/annotation_storage.d.ts +89 -0
  6. package/dist/types/src/display/api.d.ts +1472 -0
  7. package/dist/types/src/display/base_factory.d.ts +54 -0
  8. package/dist/types/src/display/canvas.d.ts +208 -0
  9. package/dist/types/src/display/display_utils.d.ts +277 -0
  10. package/dist/types/src/display/editor/annotation_editor_layer.d.ts +182 -0
  11. package/dist/types/src/display/editor/editor.d.ts +308 -0
  12. package/dist/types/src/display/editor/freetext.d.ts +72 -0
  13. package/dist/types/src/display/editor/ink.d.ts +95 -0
  14. package/dist/types/src/display/editor/stamp.d.ts +22 -0
  15. package/dist/types/src/display/editor/tools.d.ts +324 -0
  16. package/dist/types/src/display/font_loader.d.ts +43 -0
  17. package/dist/types/src/display/metadata.d.ts +11 -0
  18. package/dist/types/src/display/optional_content_config.d.ts +13 -0
  19. package/dist/types/src/display/pattern_helper.d.ts +73 -0
  20. package/dist/types/src/display/text_layer.d.ts +151 -0
  21. package/dist/types/src/display/transport_stream.d.ts +68 -0
  22. package/dist/types/src/display/worker_options.d.ts +27 -0
  23. package/dist/types/src/display/xfa_layer.d.ts +46 -0
  24. package/dist/types/src/display/xfa_text.d.ts +19 -0
  25. package/dist/types/src/pdf.d.ts +50 -0
  26. package/dist/types/src/shared/image_utils.d.ts +17 -0
  27. package/dist/types/src/shared/message_handler.d.ts +43 -0
  28. package/dist/types/src/shared/murmurhash3.d.ts +7 -0
  29. package/dist/types/src/shared/scripting_utils.d.ts +12 -0
  30. package/dist/types/src/shared/util.d.ts +396 -0
  31. package/dist/types/web/annotation_editor_layer_builder.d.ts +50 -0
  32. package/dist/types/web/annotation_layer_builder.d.ts +83 -0
  33. package/dist/types/web/app_options.d.ts +14 -0
  34. package/dist/types/web/download_manager.d.ts +14 -0
  35. package/dist/types/web/event_utils.d.ts +75 -0
  36. package/dist/types/web/generic_scripting.d.ts +8 -0
  37. package/dist/types/web/genericl10n.d.ts +13 -0
  38. package/dist/types/web/interfaces.d.ts +163 -0
  39. package/dist/types/web/l10n_utils.d.ts +7 -0
  40. package/dist/types/web/pdf_find_controller.d.ts +108 -0
  41. package/dist/types/web/pdf_find_utils.d.ts +16 -0
  42. package/dist/types/web/pdf_history.d.ts +168 -0
  43. package/dist/types/web/pdf_link_service.d.ts +243 -0
  44. package/dist/types/web/pdf_page_view.d.ts +209 -0
  45. package/dist/types/web/pdf_rendering_queue.d.ts +53 -0
  46. package/dist/types/web/pdf_scripting_manager.component.d.ts +5 -0
  47. package/dist/types/web/pdf_scripting_manager.d.ts +61 -0
  48. package/dist/types/web/pdf_single_page_viewer.d.ts +7 -0
  49. package/dist/types/web/pdf_thumbnail_view.d.ts +131 -0
  50. package/dist/types/web/pdf_thumbnail_viewer.d.ts +104 -0
  51. package/dist/types/web/pdf_viewer.component.d.ts +24 -0
  52. package/dist/types/web/pdf_viewer.d.ts +455 -0
  53. package/dist/types/web/struct_tree_layer_builder.d.ts +7 -0
  54. package/dist/types/web/text_accessibility.d.ts +42 -0
  55. package/dist/types/web/text_highlighter.d.ts +63 -0
  56. package/dist/types/web/text_layer_builder.d.ts +64 -0
  57. package/dist/types/web/ui_utils.d.ts +288 -0
  58. package/dist/types/web/xfa_layer_builder.d.ts +41 -0
  59. package/package.json +6 -7
package/README.md CHANGED
@@ -1,14 +1,10 @@
1
1
  # pdfjs-serverless
2
2
 
3
- > **Note**
4
- >
5
- > Work in progress.
6
-
7
- A redistribution of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js) for serverless enviroments, like Deno Deploy and Cloudflare Workers.
3
+ A nodeless/serverless redistribution of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js) for serverless enviroments, like Deno Deploy and Cloudflare Workers with zero dependencies.
8
4
 
9
5
  ## How It Works
10
6
 
11
- First, some string replacements of the `pdf.js` library is necessary, i.e. removing browser context references. Additionally, we enforce Node.js (might sound paradox at first, bear with me) compatibility, i.e. polyfilling the `canvas` module and setting the `isNodeJS` flag to `true`.
7
+ First, some string replacements of the `pdf.js` library is necessary, i.e. removing browser context references. Additionally, we enforce Node.js (might sound paradox at first, bear with me) compatibility, i.e. mocking the `canvas` module and setting the `isNodeJS` flag to `true`.
12
8
 
13
9
  To achieve a nodeless build, [`unenv`](https://github.com/unjs/unenv) does the heavy lifting by converting Node.js specific code to be platform-agnostic.
14
10
 
@@ -29,7 +25,7 @@ npm install pdfjs-serverless
29
25
  yarn add pdfjs-serverless
30
26
  ```
31
27
 
32
- ## Usage
28
+ ## Example Usage
33
29
 
34
30
  ### Deno
35
31
 
@@ -40,6 +36,13 @@ const data = Deno.readFileSync('./dummy.pdf')
40
36
  const doc = await getDocument(data).promise
41
37
 
42
38
  console.log(await doc.getMetadata())
39
+
40
+ for (let i = 1; i <= doc.numPages; i++) {
41
+ const page = await doc.getPage(i)
42
+ const textContent = await page.getTextContent()
43
+ const contents = textContent.items.map(item => item.str).join(' ')
44
+ console.log(contents)
45
+ }
43
46
  ```
44
47
 
45
48
  ### In Combination With `unpdf`
@@ -68,7 +71,7 @@ const { totalPages, text } = await extractPDFText(
68
71
 
69
72
  ## Inspiration
70
73
 
71
- - [`pdf.mjs`](https://github.com/bru02/pdf.mjs)
74
+ - [`pdf.mjs`](https://github.com/bru02/pdf.mjs), a nodeless build of PDF.js v2.
72
75
 
73
76
  ## License
74
77
 
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from 'pdfjs-dist/types/src/pdf.d.ts'
1
+ export * from './types/src/pdf.d.ts'
File without changes
@@ -0,0 +1,203 @@
1
+ export type PDFPageProxy = import("./api").PDFPageProxy;
2
+ export type PageViewport = import("./display_utils").PageViewport;
3
+ export type IDownloadManager = any;
4
+ export type IPDFLinkService = import("../../web/interfaces").IPDFLinkService;
5
+ export type AnnotationElementParameters = {
6
+ data: Object;
7
+ layer: HTMLDivElement;
8
+ linkService: IPDFLinkService;
9
+ downloadManager: any;
10
+ annotationStorage?: AnnotationStorage | undefined;
11
+ /**
12
+ * - Path for image resources, mainly
13
+ * for annotation icons. Include trailing slash.
14
+ */
15
+ imageResourcesPath?: string | undefined;
16
+ renderForms: boolean;
17
+ svgFactory: Object;
18
+ enableScripting?: boolean | undefined;
19
+ hasJSActions?: boolean | undefined;
20
+ fieldObjects?: Object | undefined;
21
+ };
22
+ export type AnnotationLayerParameters = {
23
+ viewport: PageViewport;
24
+ div: HTMLDivElement;
25
+ annotations: any[];
26
+ page: PDFPageProxy;
27
+ linkService: IPDFLinkService;
28
+ downloadManager: any;
29
+ annotationStorage?: AnnotationStorage | undefined;
30
+ /**
31
+ * - Path for image resources, mainly
32
+ * for annotation icons. Include trailing slash.
33
+ */
34
+ imageResourcesPath?: string | undefined;
35
+ renderForms: boolean;
36
+ /**
37
+ * - Enable embedded script execution.
38
+ */
39
+ enableScripting?: boolean | undefined;
40
+ /**
41
+ * - Some fields have JS actions.
42
+ * The default value is `false`.
43
+ */
44
+ hasJSActions?: boolean | undefined;
45
+ fieldObjects?: {
46
+ [x: string]: Object[];
47
+ } | null | undefined;
48
+ annotationCanvasMap?: Map<string, HTMLCanvasElement> | undefined;
49
+ accessibilityManager?: any;
50
+ };
51
+ /**
52
+ * @typedef {Object} AnnotationLayerParameters
53
+ * @property {PageViewport} viewport
54
+ * @property {HTMLDivElement} div
55
+ * @property {Array} annotations
56
+ * @property {PDFPageProxy} page
57
+ * @property {IPDFLinkService} linkService
58
+ * @property {IDownloadManager} downloadManager
59
+ * @property {AnnotationStorage} [annotationStorage]
60
+ * @property {string} [imageResourcesPath] - Path for image resources, mainly
61
+ * for annotation icons. Include trailing slash.
62
+ * @property {boolean} renderForms
63
+ * @property {boolean} [enableScripting] - Enable embedded script execution.
64
+ * @property {boolean} [hasJSActions] - Some fields have JS actions.
65
+ * The default value is `false`.
66
+ * @property {Object<string, Array<Object>> | null} [fieldObjects]
67
+ * @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
68
+ * @property {TextAccessibilityManager} [accessibilityManager]
69
+ */
70
+ /**
71
+ * Manage the layer containing all the annotations.
72
+ */
73
+ export class AnnotationLayer {
74
+ constructor({ div, accessibilityManager, annotationCanvasMap, l10n, page, viewport, }: {
75
+ div: any;
76
+ accessibilityManager: any;
77
+ annotationCanvasMap: any;
78
+ l10n: any;
79
+ page: any;
80
+ viewport: any;
81
+ });
82
+ div: any;
83
+ l10n: any;
84
+ page: any;
85
+ viewport: any;
86
+ zIndex: number;
87
+ popupShow: any[] | undefined;
88
+ /**
89
+ * Render a new annotation layer with all annotation elements.
90
+ *
91
+ * @param {AnnotationLayerParameters} params
92
+ * @memberof AnnotationLayer
93
+ */
94
+ render(params: AnnotationLayerParameters): Promise<void>;
95
+ /**
96
+ * Update the annotation elements on existing annotation layer.
97
+ *
98
+ * @param {AnnotationLayerParameters} viewport
99
+ * @memberof AnnotationLayer
100
+ */
101
+ update({ viewport }: AnnotationLayerParameters): void;
102
+ getEditableAnnotations(): any[];
103
+ getEditableAnnotation(id: any): any;
104
+ #private;
105
+ }
106
+ export class FreeTextAnnotationElement extends AnnotationElement {
107
+ constructor(parameters: any);
108
+ textContent: any;
109
+ textPosition: any;
110
+ annotationEditorType: number;
111
+ render(): HTMLElement | undefined;
112
+ }
113
+ export class InkAnnotationElement extends AnnotationElement {
114
+ constructor(parameters: any);
115
+ containerClassName: string;
116
+ svgElementName: string;
117
+ annotationEditorType: number;
118
+ render(): HTMLElement | undefined;
119
+ getElementsToTriggerPopup(): any[];
120
+ #private;
121
+ }
122
+ export class StampAnnotationElement extends AnnotationElement {
123
+ constructor(parameters: any);
124
+ render(): HTMLElement | undefined;
125
+ }
126
+ import { AnnotationStorage } from "./annotation_storage.js";
127
+ declare class AnnotationElement {
128
+ constructor(parameters: any, { isRenderable, ignoreBorder, createQuadrilaterals, }?: {
129
+ isRenderable?: boolean | undefined;
130
+ ignoreBorder?: boolean | undefined;
131
+ createQuadrilaterals?: boolean | undefined;
132
+ });
133
+ isRenderable: boolean;
134
+ data: any;
135
+ layer: any;
136
+ linkService: any;
137
+ downloadManager: any;
138
+ imageResourcesPath: any;
139
+ renderForms: any;
140
+ svgFactory: any;
141
+ annotationStorage: any;
142
+ enableScripting: any;
143
+ hasJSActions: any;
144
+ _fieldObjects: any;
145
+ parent: any;
146
+ container: HTMLElement | undefined;
147
+ /**
148
+ * Create an empty container for the annotation's HTML element.
149
+ *
150
+ * @private
151
+ * @param {boolean} ignoreBorder
152
+ * @memberof AnnotationElement
153
+ * @returns {HTMLElement} A section element.
154
+ */
155
+ private _createContainer;
156
+ setRotation(angle: any, container?: HTMLElement | undefined): void;
157
+ get _commonActions(): any;
158
+ _dispatchEventFromSandbox(actions: any, jsEvent: any): void;
159
+ _setDefaultPropertiesFromJS(element: any): void;
160
+ /**
161
+ * Create quadrilaterals from the annotation's quadpoints.
162
+ *
163
+ * @private
164
+ * @memberof AnnotationElement
165
+ */
166
+ private _createQuadrilaterals;
167
+ /**
168
+ * Create a popup for the annotation's HTML element. This is used for
169
+ * annotations that do not have a Popup entry in the dictionary, but
170
+ * are of a type that works with popups (such as Highlight annotations).
171
+ *
172
+ * @private
173
+ * @memberof AnnotationElement
174
+ */
175
+ private _createPopup;
176
+ /**
177
+ * Render the annotation's HTML element(s).
178
+ *
179
+ * @public
180
+ * @memberof AnnotationElement
181
+ */
182
+ public render(): void;
183
+ /**
184
+ * @private
185
+ * @returns {Array}
186
+ */
187
+ private _getElementsByName;
188
+ show(): void;
189
+ hide(): void;
190
+ /**
191
+ * Get the HTML element(s) which can trigger a popup when clicked or hovered.
192
+ *
193
+ * @public
194
+ * @memberof AnnotationElement
195
+ * @returns {Array<HTMLElement>|HTMLElement} An array of elements or an
196
+ * element.
197
+ */
198
+ public getElementsToTriggerPopup(): Array<HTMLElement> | HTMLElement;
199
+ addHighlightArea(): void;
200
+ _editOnDoubleClick(): void;
201
+ #private;
202
+ }
203
+ export {};
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Key/value storage for annotation data in forms.
3
+ */
4
+ export class AnnotationStorage {
5
+ onSetModified: any;
6
+ onResetModified: any;
7
+ onAnnotationEditor: any;
8
+ /**
9
+ * Get the value for a given key if it exists, or return the default value.
10
+ * @param {string} key
11
+ * @param {Object} defaultValue
12
+ * @returns {Object}
13
+ */
14
+ getValue(key: string, defaultValue: Object): Object;
15
+ /**
16
+ * Get the value for a given key.
17
+ * @param {string} key
18
+ * @returns {Object}
19
+ */
20
+ getRawValue(key: string): Object;
21
+ /**
22
+ * Remove a value from the storage.
23
+ * @param {string} key
24
+ */
25
+ remove(key: string): void;
26
+ /**
27
+ * Set the value for a given key
28
+ * @param {string} key
29
+ * @param {Object} value
30
+ */
31
+ setValue(key: string, value: Object): void;
32
+ /**
33
+ * Check if the storage contains the given key.
34
+ * @param {string} key
35
+ * @returns {boolean}
36
+ */
37
+ has(key: string): boolean;
38
+ /**
39
+ * @returns {Object | null}
40
+ */
41
+ getAll(): Object | null;
42
+ /**
43
+ * @param {Object} obj
44
+ */
45
+ setAll(obj: Object): void;
46
+ get size(): number;
47
+ resetModified(): void;
48
+ /**
49
+ * @returns {PrintAnnotationStorage}
50
+ */
51
+ get print(): PrintAnnotationStorage;
52
+ /**
53
+ * PLEASE NOTE: Only intended for usage within the API itself.
54
+ * @ignore
55
+ */
56
+ get serializable(): Readonly<{
57
+ map: null;
58
+ hash: "";
59
+ transfers: undefined;
60
+ }> | {
61
+ map: Map<any, any>;
62
+ hash: string;
63
+ transfers: any[];
64
+ };
65
+ #private;
66
+ }
67
+ /**
68
+ * A special `AnnotationStorage` for use during printing, where the serializable
69
+ * data is *frozen* upon initialization, to prevent scripting from modifying its
70
+ * contents. (Necessary since printing is triggered synchronously in browsers.)
71
+ */
72
+ export class PrintAnnotationStorage extends AnnotationStorage {
73
+ constructor(parent: any);
74
+ /**
75
+ * PLEASE NOTE: Only intended for usage within the API itself.
76
+ * @ignore
77
+ */
78
+ get serializable(): {
79
+ map: any;
80
+ hash: any;
81
+ transfers: any;
82
+ };
83
+ #private;
84
+ }
85
+ export const SerializableEmpty: Readonly<{
86
+ map: null;
87
+ hash: "";
88
+ transfers: undefined;
89
+ }>;