unpdf 0.9.0 → 0.10.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.
package/README.md CHANGED
@@ -87,10 +87,11 @@ for (let i = 1; i <= doc.numPages; i++) {
87
87
  Generally speaking, you don't need to worry about the PDF.js build. `unpdf` ships with a serverless build of the latest PDF.js version. However, if you want to use the official PDF.js version or the legacy build, you can define a custom PDF.js module.
88
88
 
89
89
  ```ts
90
- // Before using any other methods, define the PDF.js module
91
- import { defineUnPDFConfig } from "unpdf";
90
+ // Before using any other method, define the PDF.js module
91
+ // if you need another PDF.js build
92
+ import { configureUnPDF } from "unpdf";
92
93
 
93
- defineUnPDFConfig({
94
+ configureUnPDF({
94
95
  // Use the official PDF.js build (make sure to install it first)
95
96
  pdfjs: () => import("pdfjs-dist"),
96
97
  });
@@ -118,12 +119,12 @@ interface UnPDFConfiguration {
118
119
 
119
120
  ## Methods
120
121
 
121
- ### `defineUnPDFConfig`
122
+ ### `configureUnPDF`
122
123
 
123
124
  Define a custom PDF.js module, like the legacy build. Make sure to call this method before using any other methods.
124
125
 
125
126
  ```ts
126
- function defineUnPDFConfig(config: UnPDFConfiguration): Promise<void>;
127
+ function configureUnPDF(config: UnPDFConfiguration): Promise<void>;
127
128
  ```
128
129
 
129
130
  ### `getResolvedPDFJS`
@@ -172,9 +173,9 @@ In order to use this method, you have to meet the following requirements:
172
173
  **Example**
173
174
 
174
175
  ```ts
175
- import { defineUnPDFConfig, renderPageAsImage } from "unpdf";
176
+ import { configureUnPDF, renderPageAsImage } from "unpdf";
176
177
 
177
- defineUnPDFConfig({
178
+ configureUnPDF({
178
179
  // Use the official PDF.js build
179
180
  pdfjs: () => import("pdfjs-dist"),
180
181
  });
package/dist/index.cjs CHANGED
@@ -8,6 +8,8 @@ async function getDocumentProxy(data, options = {}) {
8
8
  const pdf = await getDocument({
9
9
  data,
10
10
  isEvalSupported: false,
11
+ // See: https://github.com/mozilla/pdf.js/issues/4244#issuecomment-1479534301
12
+ useSystemFonts: true,
11
13
  ...options
12
14
  }).promise;
13
15
  return pdf;
@@ -140,7 +142,8 @@ async function createIsomorphicCanvasFactory(canvas) {
140
142
  canvas2.width = width;
141
143
  canvas2.height = height;
142
144
  return canvas2;
143
- } else if (isNode) {
145
+ }
146
+ if (isNode) {
144
147
  if (!_canvas) {
145
148
  throw new Error('Failed to resolve "canvas" package.');
146
149
  }
@@ -175,13 +178,14 @@ async function createIsomorphicCanvasFactory(canvas) {
175
178
  };
176
179
  }
177
180
 
178
- async function defineUnPDFConfig(options) {
181
+ async function configureUnPDF(options) {
179
182
  const { pdfjs } = { ...options };
180
183
  if (pdfjs) {
181
184
  await resolvePDFJSImports(pdfjs, { force: true });
182
185
  }
183
186
  }
184
187
 
188
+ const defineUnPDFConfig = configureUnPDF;
185
189
  const getMeta = async (...args) => {
186
190
  await resolvePDFJSImports();
187
191
  return await getMeta$1(...args);
@@ -190,7 +194,6 @@ const extractText = async (...args) => {
190
194
  await resolvePDFJSImports();
191
195
  return await extractText$1(...args);
192
196
  };
193
- const extractPDFText = extractText;
194
197
  const extractImages = async (...args) => {
195
198
  await resolvePDFJSImports();
196
199
  return await extractImages$1(...args);
@@ -200,9 +203,9 @@ const renderPageAsImage = async (...args) => {
200
203
  return await renderPageAsImage$1(...args);
201
204
  };
202
205
 
206
+ exports.configureUnPDF = configureUnPDF;
203
207
  exports.defineUnPDFConfig = defineUnPDFConfig;
204
208
  exports.extractImages = extractImages;
205
- exports.extractPDFText = extractPDFText;
206
209
  exports.extractText = extractText;
207
210
  exports.getDocumentProxy = getDocumentProxy;
208
211
  exports.getMeta = getMeta;
package/dist/index.d.cts CHANGED
@@ -37,13 +37,14 @@ interface UnPDFConfiguration {
37
37
  pdfjs?: () => Promise<any>;
38
38
  }
39
39
 
40
- declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
40
+ declare function configureUnPDF(options: UnPDFConfiguration): Promise<void>;
41
41
 
42
42
  /**
43
43
  * Returns a PDFDocumentProxy instance from a given binary data.
44
44
  *
45
45
  * Applies the following defaults:
46
46
  * - `isEvalSupported: false`
47
+ * - `useSystemFonts: true`
47
48
  */
48
49
  declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
49
50
  declare function getResolvedPDFJS(): Promise<PDFJS>;
@@ -51,11 +52,12 @@ declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<any>, { force
51
52
  force?: boolean | undefined;
52
53
  }): Promise<void>;
53
54
 
55
+ /** @deprecated Use `configureUnPDF` instead */
56
+ declare const defineUnPDFConfig: typeof configureUnPDF;
57
+
54
58
  declare const getMeta: typeof getMeta$1;
55
59
  declare const extractText: typeof extractText$1;
56
- /** @deprecated Use `extractText` instead. */
57
- declare const extractPDFText: typeof extractText$1;
58
60
  declare const extractImages: typeof extractImages$1;
59
61
  declare const renderPageAsImage: typeof renderPageAsImage$1;
60
62
 
61
- export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
63
+ export { configureUnPDF, defineUnPDFConfig, extractImages, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
package/dist/index.d.mts CHANGED
@@ -37,13 +37,14 @@ interface UnPDFConfiguration {
37
37
  pdfjs?: () => Promise<any>;
38
38
  }
39
39
 
40
- declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
40
+ declare function configureUnPDF(options: UnPDFConfiguration): Promise<void>;
41
41
 
42
42
  /**
43
43
  * Returns a PDFDocumentProxy instance from a given binary data.
44
44
  *
45
45
  * Applies the following defaults:
46
46
  * - `isEvalSupported: false`
47
+ * - `useSystemFonts: true`
47
48
  */
48
49
  declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
49
50
  declare function getResolvedPDFJS(): Promise<PDFJS>;
@@ -51,11 +52,12 @@ declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<any>, { force
51
52
  force?: boolean | undefined;
52
53
  }): Promise<void>;
53
54
 
55
+ /** @deprecated Use `configureUnPDF` instead */
56
+ declare const defineUnPDFConfig: typeof configureUnPDF;
57
+
54
58
  declare const getMeta: typeof getMeta$1;
55
59
  declare const extractText: typeof extractText$1;
56
- /** @deprecated Use `extractText` instead. */
57
- declare const extractPDFText: typeof extractText$1;
58
60
  declare const extractImages: typeof extractImages$1;
59
61
  declare const renderPageAsImage: typeof renderPageAsImage$1;
60
62
 
61
- export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
63
+ export { configureUnPDF, defineUnPDFConfig, extractImages, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
package/dist/index.d.ts CHANGED
@@ -37,13 +37,14 @@ interface UnPDFConfiguration {
37
37
  pdfjs?: () => Promise<any>;
38
38
  }
39
39
 
40
- declare function defineUnPDFConfig(options: UnPDFConfiguration): Promise<void>;
40
+ declare function configureUnPDF(options: UnPDFConfiguration): Promise<void>;
41
41
 
42
42
  /**
43
43
  * Returns a PDFDocumentProxy instance from a given binary data.
44
44
  *
45
45
  * Applies the following defaults:
46
46
  * - `isEvalSupported: false`
47
+ * - `useSystemFonts: true`
47
48
  */
48
49
  declare function getDocumentProxy(data: BinaryData, options?: DocumentInitParameters): Promise<PDFDocumentProxy>;
49
50
  declare function getResolvedPDFJS(): Promise<PDFJS>;
@@ -51,11 +52,12 @@ declare function resolvePDFJSImports(pdfjsResolver?: () => Promise<any>, { force
51
52
  force?: boolean | undefined;
52
53
  }): Promise<void>;
53
54
 
55
+ /** @deprecated Use `configureUnPDF` instead */
56
+ declare const defineUnPDFConfig: typeof configureUnPDF;
57
+
54
58
  declare const getMeta: typeof getMeta$1;
55
59
  declare const extractText: typeof extractText$1;
56
- /** @deprecated Use `extractText` instead. */
57
- declare const extractPDFText: typeof extractText$1;
58
60
  declare const extractImages: typeof extractImages$1;
59
61
  declare const renderPageAsImage: typeof renderPageAsImage$1;
60
62
 
61
- export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
63
+ export { configureUnPDF, defineUnPDFConfig, extractImages, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
package/dist/index.mjs CHANGED
@@ -6,6 +6,8 @@ async function getDocumentProxy(data, options = {}) {
6
6
  const pdf = await getDocument({
7
7
  data,
8
8
  isEvalSupported: false,
9
+ // See: https://github.com/mozilla/pdf.js/issues/4244#issuecomment-1479534301
10
+ useSystemFonts: true,
9
11
  ...options
10
12
  }).promise;
11
13
  return pdf;
@@ -138,7 +140,8 @@ async function createIsomorphicCanvasFactory(canvas) {
138
140
  canvas2.width = width;
139
141
  canvas2.height = height;
140
142
  return canvas2;
141
- } else if (isNode) {
143
+ }
144
+ if (isNode) {
142
145
  if (!_canvas) {
143
146
  throw new Error('Failed to resolve "canvas" package.');
144
147
  }
@@ -173,13 +176,14 @@ async function createIsomorphicCanvasFactory(canvas) {
173
176
  };
174
177
  }
175
178
 
176
- async function defineUnPDFConfig(options) {
179
+ async function configureUnPDF(options) {
177
180
  const { pdfjs } = { ...options };
178
181
  if (pdfjs) {
179
182
  await resolvePDFJSImports(pdfjs, { force: true });
180
183
  }
181
184
  }
182
185
 
186
+ const defineUnPDFConfig = configureUnPDF;
183
187
  const getMeta = async (...args) => {
184
188
  await resolvePDFJSImports();
185
189
  return await getMeta$1(...args);
@@ -188,7 +192,6 @@ const extractText = async (...args) => {
188
192
  await resolvePDFJSImports();
189
193
  return await extractText$1(...args);
190
194
  };
191
- const extractPDFText = extractText;
192
195
  const extractImages = async (...args) => {
193
196
  await resolvePDFJSImports();
194
197
  return await extractImages$1(...args);
@@ -198,4 +201,4 @@ const renderPageAsImage = async (...args) => {
198
201
  return await renderPageAsImage$1(...args);
199
202
  };
200
203
 
201
- export { defineUnPDFConfig, extractImages, extractPDFText, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
204
+ export { configureUnPDF, defineUnPDFConfig, extractImages, extractText, getDocumentProxy, getMeta, getResolvedPDFJS, renderPageAsImage, resolvePDFJSImports };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unpdf",
3
3
  "type": "module",
4
- "version": "0.9.0",
4
+ "version": "0.10.0",
5
5
  "packageManager": "pnpm@8.10.2",
6
6
  "description": "Utilities to work with PDFs in Node.js, browser and workers",
7
7
  "author": "Johann Schopplich <pkg@johannschopplich.com>",