unpdf 0.5.4 → 0.6.1

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 (88) hide show
  1. package/README.md +65 -31
  2. package/dist/index.cjs +120 -0
  3. package/dist/index.d.cts +49 -0
  4. package/dist/index.d.mts +49 -0
  5. package/dist/index.d.ts +49 -0
  6. package/dist/index.mjs +112 -0
  7. package/dist/pdfjs.d.mts +1 -0
  8. package/dist/pdfjs.d.ts +1 -0
  9. package/dist/pdfjs.mjs +1 -0
  10. package/dist/types/external/webL10n/l10n.d.ts +0 -0
  11. package/dist/types/src/display/annotation_layer.d.ts +203 -0
  12. package/dist/types/src/display/annotation_storage.d.ts +89 -0
  13. package/dist/types/src/display/api.d.ts +1466 -0
  14. package/dist/types/src/display/base_factory.d.ts +54 -0
  15. package/dist/types/src/display/canvas.d.ts +208 -0
  16. package/dist/types/src/display/display_utils.d.ts +277 -0
  17. package/dist/types/src/display/editor/annotation_editor_layer.d.ts +196 -0
  18. package/dist/types/src/display/editor/editor.d.ts +325 -0
  19. package/dist/types/src/display/editor/freetext.d.ts +72 -0
  20. package/dist/types/src/display/editor/ink.d.ts +95 -0
  21. package/dist/types/src/display/editor/stamp.d.ts +28 -0
  22. package/dist/types/src/display/editor/tools.d.ts +349 -0
  23. package/dist/types/src/display/font_loader.d.ts +43 -0
  24. package/dist/types/src/display/metadata.d.ts +11 -0
  25. package/dist/types/src/display/optional_content_config.d.ts +13 -0
  26. package/dist/types/src/display/pattern_helper.d.ts +73 -0
  27. package/dist/types/src/display/text_layer.d.ts +151 -0
  28. package/dist/types/src/display/transport_stream.d.ts +68 -0
  29. package/dist/types/src/display/worker_options.d.ts +27 -0
  30. package/dist/types/src/display/xfa_layer.d.ts +46 -0
  31. package/dist/types/src/display/xfa_text.d.ts +19 -0
  32. package/dist/types/src/pdf.d.ts +50 -0
  33. package/dist/types/src/shared/image_utils.d.ts +17 -0
  34. package/dist/types/src/shared/message_handler.d.ts +43 -0
  35. package/dist/types/src/shared/murmurhash3.d.ts +7 -0
  36. package/dist/types/src/shared/scripting_utils.d.ts +16 -0
  37. package/dist/types/src/shared/util.d.ts +398 -0
  38. package/dist/types/web/annotation_editor_layer_builder.d.ts +50 -0
  39. package/dist/types/web/annotation_layer_builder.d.ts +83 -0
  40. package/dist/types/web/app_options.d.ts +14 -0
  41. package/dist/types/web/download_manager.d.ts +14 -0
  42. package/dist/types/web/event_utils.d.ts +75 -0
  43. package/dist/types/web/generic_scripting.d.ts +8 -0
  44. package/dist/types/web/genericl10n.d.ts +13 -0
  45. package/dist/types/web/interfaces.d.ts +163 -0
  46. package/dist/types/web/l10n_utils.d.ts +7 -0
  47. package/dist/types/web/pdf_find_controller.d.ts +108 -0
  48. package/dist/types/web/pdf_find_utils.d.ts +16 -0
  49. package/dist/types/web/pdf_history.d.ts +168 -0
  50. package/dist/types/web/pdf_link_service.d.ts +243 -0
  51. package/dist/types/web/pdf_page_view.d.ts +209 -0
  52. package/dist/types/web/pdf_rendering_queue.d.ts +53 -0
  53. package/dist/types/web/pdf_scripting_manager.component.d.ts +5 -0
  54. package/dist/types/web/pdf_scripting_manager.d.ts +61 -0
  55. package/dist/types/web/pdf_single_page_viewer.d.ts +7 -0
  56. package/dist/types/web/pdf_thumbnail_view.d.ts +131 -0
  57. package/dist/types/web/pdf_thumbnail_viewer.d.ts +104 -0
  58. package/dist/types/web/pdf_viewer.component.d.ts +24 -0
  59. package/dist/types/web/pdf_viewer.d.ts +455 -0
  60. package/dist/types/web/struct_tree_layer_builder.d.ts +7 -0
  61. package/dist/types/web/text_accessibility.d.ts +42 -0
  62. package/dist/types/web/text_highlighter.d.ts +63 -0
  63. package/dist/types/web/text_layer_builder.d.ts +64 -0
  64. package/dist/types/web/ui_utils.d.ts +288 -0
  65. package/dist/types/web/xfa_layer_builder.d.ts +41 -0
  66. package/package.json +54 -44
  67. package/dist/index.node.cjs +0 -25
  68. package/dist/index.node.d.cts +0 -10
  69. package/dist/index.node.d.mts +0 -10
  70. package/dist/index.node.d.ts +0 -10
  71. package/dist/index.node.mjs +0 -18
  72. package/dist/index.web.cjs +0 -25
  73. package/dist/index.web.d.cts +0 -10
  74. package/dist/index.web.d.mts +0 -10
  75. package/dist/index.web.d.ts +0 -10
  76. package/dist/index.web.mjs +0 -18
  77. package/dist/index.worker.cjs +0 -21
  78. package/dist/index.worker.d.cts +0 -10
  79. package/dist/index.worker.d.mts +0 -10
  80. package/dist/index.worker.d.ts +0 -10
  81. package/dist/index.worker.mjs +0 -13
  82. package/dist/shared/unpdf.3dcacb97.mjs +0 -49
  83. package/dist/shared/unpdf.42987ff1.cjs +0 -52
  84. package/dist/shared/unpdf.6363738c.d.cts +0 -43
  85. package/dist/shared/unpdf.6363738c.d.mts +0 -43
  86. package/dist/shared/unpdf.6363738c.d.ts +0 -43
  87. package/dist/shared/unpdf.ab6a2535.mjs +0 -46
  88. package/dist/shared/unpdf.eba9a3dc.cjs +0 -53
@@ -1,10 +0,0 @@
1
- import { g as getPDFMeta$1, e as extractPDFText$1, a as getImagesFromPage$1 } from './shared/unpdf.6363738c.js';
2
- export { d as defineUnPDFConfig, b as getDocumentProxy, c as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.6363738c.js';
3
- import 'pdfjs-dist/types/src/display/api';
4
- import 'pdfjs-dist';
5
-
6
- declare const getPDFMeta: typeof getPDFMeta$1;
7
- declare const extractPDFText: typeof extractPDFText$1;
8
- declare const getImagesFromPage: typeof getImagesFromPage$1;
9
-
10
- export { extractPDFText, getImagesFromPage, getPDFMeta };
@@ -1,13 +0,0 @@
1
- export { d as defineUnPDFConfig, g as getDocumentProxy, a as getResolvedPDFJS, r as resolvePDFJSImports } from './shared/unpdf.ab6a2535.mjs';
2
-
3
- const getPDFMeta = async () => {
4
- throw new Error("Not implemented in worker context yet");
5
- };
6
- const extractPDFText = async () => {
7
- throw new Error("Not implemented in worker context yet");
8
- };
9
- const getImagesFromPage = async () => {
10
- throw new Error("Not implemented in worker context yet");
11
- };
12
-
13
- export { extractPDFText, getImagesFromPage, getPDFMeta };
@@ -1,49 +0,0 @@
1
- import { i as isPDFDocumentProxy, g as getDocumentProxy, a as getResolvedPDFJS } from './unpdf.ab6a2535.mjs';
2
-
3
- async function getPDFMeta(data) {
4
- const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
5
- const meta = await pdf.getMetadata().catch(() => null);
6
- return {
7
- info: meta?.info ?? {},
8
- metadata: meta?.metadata?.getAll() ?? {}
9
- };
10
- }
11
-
12
- async function extractPDFText(data, options = {}) {
13
- const { mergePages = false } = { ...options };
14
- const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
15
- const texts = await Promise.all(
16
- Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
17
- );
18
- const filteredTexts = texts.filter(Boolean);
19
- return {
20
- totalPages: pdf.numPages,
21
- text: mergePages ? filteredTexts.join("\n\n") : filteredTexts
22
- };
23
- }
24
- async function getPageText(pdf, pageNumber) {
25
- const page = await pdf.getPage(pageNumber);
26
- const content = await page.getTextContent();
27
- const items = content.items;
28
- if (items.length === 0)
29
- return;
30
- return items.map(({ str }) => str).join("\n");
31
- }
32
-
33
- async function getImagesFromPage(data, pageNumber) {
34
- const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
35
- const page = await pdf.getPage(pageNumber);
36
- const operatorList = await page.getOperatorList();
37
- const { OPS } = await getResolvedPDFJS();
38
- const images = [];
39
- for (const op of operatorList.fnArray) {
40
- if (op !== OPS.paintImageXObject)
41
- continue;
42
- const image = await page.objs.get(operatorList.argsArray[op][0]);
43
- if (image.data)
44
- images.push(image.data.buffer);
45
- }
46
- return images;
47
- }
48
-
49
- export { getImagesFromPage as a, extractPDFText as e, getPDFMeta as g };
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- let resolvedModule;
4
- async function getDocumentProxy(data, options = {}) {
5
- const { getDocument } = await getResolvedPDFJS();
6
- const pdf = await getDocument({
7
- data,
8
- useWorkerFetch: false,
9
- isEvalSupported: false,
10
- useSystemFonts: true,
11
- ...options
12
- }).promise;
13
- return pdf;
14
- }
15
- async function defineUnPDFConfig(options) {
16
- const { pdfjs } = { ...options };
17
- if (pdfjs)
18
- await resolvePDFJSImports(pdfjs);
19
- }
20
- async function getResolvedPDFJS() {
21
- if (!resolvedModule)
22
- await resolvePDFJSImports();
23
- return resolvedModule;
24
- }
25
- async function resolvePDFJSImports(pdfjs) {
26
- if (resolvedModule)
27
- return;
28
- if (pdfjs) {
29
- try {
30
- const { default: mod } = await pdfjs();
31
- resolvedModule = mod;
32
- return;
33
- } catch (error) {
34
- throw new Error("Resolving PDF.js failed. Please check the provided configuration.");
35
- }
36
- }
37
- try {
38
- const { default: mod } = await import('pdfjs-dist');
39
- resolvedModule = mod;
40
- } catch (error) {
41
- throw new Error("PDF.js is not available. Please add the package as a dependency.");
42
- }
43
- }
44
- function isPDFDocumentProxy(data) {
45
- return typeof data === "object" && data !== null && "_pdfInfo" in data;
46
- }
47
-
48
- exports.defineUnPDFConfig = defineUnPDFConfig;
49
- exports.getDocumentProxy = getDocumentProxy;
50
- exports.getResolvedPDFJS = getResolvedPDFJS;
51
- exports.isPDFDocumentProxy = isPDFDocumentProxy;
52
- exports.resolvePDFJSImports = resolvePDFJSImports;
@@ -1,43 +0,0 @@
1
- import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
2
- import PDFJS from 'pdfjs-dist';
3
-
4
- declare function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
5
- info: Record<string, any>;
6
- metadata: Record<string, any>;
7
- }>;
8
-
9
- declare function extractPDFText(data: BinaryData | PDFDocumentProxy, options?: {
10
- mergePages?: boolean;
11
- }): Promise<{
12
- totalPages: number;
13
- text: string | string[];
14
- }>;
15
-
16
- declare function getImagesFromPage(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<ArrayBuffer[]>;
17
-
18
- interface UnPDFConfiguration {
19
- /**
20
- * By default, UnPDF will use the latest version of PDF.js. If you want to
21
- * use an older version or the legacy build, set a promise that resolves to
22
- * the PDF.js module.
23
- *
24
- * @example
25
- * () => import('pdfjs-dist/legacy/build/pdf.js')
26
- */
27
- pdfjs?: () => Promise<typeof PDFJS>;
28
- }
29
-
30
- /**
31
- * Returns a PDFDocumentProxy instance from a given binary data.
32
- *
33
- * Applies the following defaults:
34
- * - `useWorkerFetch: false`
35
- * - `isEvalSupported: false`
36
- * - `useSystemFonts: true`
37
- */
38
- declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
39
- declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
40
- declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
41
- declare function resolvePDFJSImports(pdfjs?: () => Promise<typeof PDFJS>): Promise<void>;
42
-
43
- export { getImagesFromPage as a, getDocumentProxy as b, getResolvedPDFJS as c, defineUnPDFConfig as d, extractPDFText as e, getPDFMeta as g, resolvePDFJSImports as r };
@@ -1,43 +0,0 @@
1
- import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
2
- import PDFJS from 'pdfjs-dist';
3
-
4
- declare function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
5
- info: Record<string, any>;
6
- metadata: Record<string, any>;
7
- }>;
8
-
9
- declare function extractPDFText(data: BinaryData | PDFDocumentProxy, options?: {
10
- mergePages?: boolean;
11
- }): Promise<{
12
- totalPages: number;
13
- text: string | string[];
14
- }>;
15
-
16
- declare function getImagesFromPage(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<ArrayBuffer[]>;
17
-
18
- interface UnPDFConfiguration {
19
- /**
20
- * By default, UnPDF will use the latest version of PDF.js. If you want to
21
- * use an older version or the legacy build, set a promise that resolves to
22
- * the PDF.js module.
23
- *
24
- * @example
25
- * () => import('pdfjs-dist/legacy/build/pdf.js')
26
- */
27
- pdfjs?: () => Promise<typeof PDFJS>;
28
- }
29
-
30
- /**
31
- * Returns a PDFDocumentProxy instance from a given binary data.
32
- *
33
- * Applies the following defaults:
34
- * - `useWorkerFetch: false`
35
- * - `isEvalSupported: false`
36
- * - `useSystemFonts: true`
37
- */
38
- declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
39
- declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
40
- declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
41
- declare function resolvePDFJSImports(pdfjs?: () => Promise<typeof PDFJS>): Promise<void>;
42
-
43
- export { getImagesFromPage as a, getDocumentProxy as b, getResolvedPDFJS as c, defineUnPDFConfig as d, extractPDFText as e, getPDFMeta as g, resolvePDFJSImports as r };
@@ -1,43 +0,0 @@
1
- import { BinaryData, PDFDocumentProxy, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
2
- import PDFJS from 'pdfjs-dist';
3
-
4
- declare function getPDFMeta(data: BinaryData | PDFDocumentProxy): Promise<{
5
- info: Record<string, any>;
6
- metadata: Record<string, any>;
7
- }>;
8
-
9
- declare function extractPDFText(data: BinaryData | PDFDocumentProxy, options?: {
10
- mergePages?: boolean;
11
- }): Promise<{
12
- totalPages: number;
13
- text: string | string[];
14
- }>;
15
-
16
- declare function getImagesFromPage(data: BinaryData | PDFDocumentProxy, pageNumber: number): Promise<ArrayBuffer[]>;
17
-
18
- interface UnPDFConfiguration {
19
- /**
20
- * By default, UnPDF will use the latest version of PDF.js. If you want to
21
- * use an older version or the legacy build, set a promise that resolves to
22
- * the PDF.js module.
23
- *
24
- * @example
25
- * () => import('pdfjs-dist/legacy/build/pdf.js')
26
- */
27
- pdfjs?: () => Promise<typeof PDFJS>;
28
- }
29
-
30
- /**
31
- * Returns a PDFDocumentProxy instance from a given binary data.
32
- *
33
- * Applies the following defaults:
34
- * - `useWorkerFetch: false`
35
- * - `isEvalSupported: false`
36
- * - `useSystemFonts: true`
37
- */
38
- declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
39
- declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
40
- declare function getResolvedPDFJS(): Promise<typeof PDFJS>;
41
- declare function resolvePDFJSImports(pdfjs?: () => Promise<typeof PDFJS>): Promise<void>;
42
-
43
- export { getImagesFromPage as a, getDocumentProxy as b, getResolvedPDFJS as c, defineUnPDFConfig as d, extractPDFText as e, getPDFMeta as g, resolvePDFJSImports as r };
@@ -1,46 +0,0 @@
1
- let resolvedModule;
2
- async function getDocumentProxy(data, options = {}) {
3
- const { getDocument } = await getResolvedPDFJS();
4
- const pdf = await getDocument({
5
- data,
6
- useWorkerFetch: false,
7
- isEvalSupported: false,
8
- useSystemFonts: true,
9
- ...options
10
- }).promise;
11
- return pdf;
12
- }
13
- async function defineUnPDFConfig(options) {
14
- const { pdfjs } = { ...options };
15
- if (pdfjs)
16
- await resolvePDFJSImports(pdfjs);
17
- }
18
- async function getResolvedPDFJS() {
19
- if (!resolvedModule)
20
- await resolvePDFJSImports();
21
- return resolvedModule;
22
- }
23
- async function resolvePDFJSImports(pdfjs) {
24
- if (resolvedModule)
25
- return;
26
- if (pdfjs) {
27
- try {
28
- const { default: mod } = await pdfjs();
29
- resolvedModule = mod;
30
- return;
31
- } catch (error) {
32
- throw new Error("Resolving PDF.js failed. Please check the provided configuration.");
33
- }
34
- }
35
- try {
36
- const { default: mod } = await import('pdfjs-dist');
37
- resolvedModule = mod;
38
- } catch (error) {
39
- throw new Error("PDF.js is not available. Please add the package as a dependency.");
40
- }
41
- }
42
- function isPDFDocumentProxy(data) {
43
- return typeof data === "object" && data !== null && "_pdfInfo" in data;
44
- }
45
-
46
- export { getResolvedPDFJS as a, defineUnPDFConfig as d, getDocumentProxy as g, isPDFDocumentProxy as i, resolvePDFJSImports as r };
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- const utils = require('./unpdf.42987ff1.cjs');
4
-
5
- async function getPDFMeta(data) {
6
- const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
7
- const meta = await pdf.getMetadata().catch(() => null);
8
- return {
9
- info: meta?.info ?? {},
10
- metadata: meta?.metadata?.getAll() ?? {}
11
- };
12
- }
13
-
14
- async function extractPDFText(data, options = {}) {
15
- const { mergePages = false } = { ...options };
16
- const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
17
- const texts = await Promise.all(
18
- Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
19
- );
20
- const filteredTexts = texts.filter(Boolean);
21
- return {
22
- totalPages: pdf.numPages,
23
- text: mergePages ? filteredTexts.join("\n\n") : filteredTexts
24
- };
25
- }
26
- async function getPageText(pdf, pageNumber) {
27
- const page = await pdf.getPage(pageNumber);
28
- const content = await page.getTextContent();
29
- const items = content.items;
30
- if (items.length === 0)
31
- return;
32
- return items.map(({ str }) => str).join("\n");
33
- }
34
-
35
- async function getImagesFromPage(data, pageNumber) {
36
- const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
37
- const page = await pdf.getPage(pageNumber);
38
- const operatorList = await page.getOperatorList();
39
- const { OPS } = await utils.getResolvedPDFJS();
40
- const images = [];
41
- for (const op of operatorList.fnArray) {
42
- if (op !== OPS.paintImageXObject)
43
- continue;
44
- const image = await page.objs.get(operatorList.argsArray[op][0]);
45
- if (image.data)
46
- images.push(image.data.buffer);
47
- }
48
- return images;
49
- }
50
-
51
- exports.extractPDFText = extractPDFText;
52
- exports.getImagesFromPage = getImagesFromPage;
53
- exports.getPDFMeta = getPDFMeta;