unpdf 1.0.3 → 1.0.5
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 +6 -11
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -69,12 +69,13 @@ Usually you don't need to worry about the PDF.js build. `unpdf` ships with a ser
|
|
|
69
69
|
For example, if you want to use the official PDF.js build, you can do the following:
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
|
-
import { definePDFJSModule } from 'unpdf'
|
|
72
|
+
import { definePDFJSModule, extractText, getDocumentProxy } from 'unpdf'
|
|
73
73
|
|
|
74
74
|
// Define the PDF.js build before using any other unpdf method
|
|
75
75
|
await definePDFJSModule(() => import('pdfjs-dist'))
|
|
76
76
|
|
|
77
77
|
// Now, you can use all unpdf methods with the official PDF.js build
|
|
78
|
+
const pdf = await getDocumentProxy(/* … */)
|
|
78
79
|
const { text } = await extractText(pdf)
|
|
79
80
|
```
|
|
80
81
|
|
|
@@ -93,23 +94,17 @@ const { version } = await getResolvedPDFJS()
|
|
|
93
94
|
> [!NOTE]
|
|
94
95
|
> If no other PDF.js build was defined, the serverless build will always be used.
|
|
95
96
|
|
|
96
|
-
For example, you can use the `getDocument` method to load a PDF file and then use the `
|
|
97
|
+
For example, you can use the `getDocument` method to load a PDF file and then use the `getMetadata` method to get the metadata of the PDF file:
|
|
97
98
|
|
|
98
99
|
```ts
|
|
100
|
+
import { readFile } from 'node:fs/promises'
|
|
99
101
|
import { getResolvedPDFJS } from 'unpdf'
|
|
100
102
|
|
|
101
103
|
const { getDocument } = await getResolvedPDFJS()
|
|
102
|
-
const data =
|
|
103
|
-
const document = await getDocument(data).promise
|
|
104
|
+
const data = await readFile('./dummy.pdf')
|
|
105
|
+
const document = await getDocument(new Uint8Array(data)).promise
|
|
104
106
|
|
|
105
107
|
console.log(await document.getMetadata())
|
|
106
|
-
|
|
107
|
-
for (let i = 1; i <= document.numPages; i++) {
|
|
108
|
-
const page = await document.getPage(i)
|
|
109
|
-
const textContent = await page.getTextContent()
|
|
110
|
-
const contents = textContent.items.map(item => item.str).join(' ')
|
|
111
|
-
console.log(contents)
|
|
112
|
-
}
|
|
113
108
|
```
|
|
114
109
|
|
|
115
110
|
## API
|
package/dist/index.cjs
CHANGED
|
@@ -145,7 +145,7 @@ async function extractImages$1(data, pageNumber) {
|
|
|
145
145
|
continue;
|
|
146
146
|
}
|
|
147
147
|
const imageKey = operatorList.argsArray[i][0];
|
|
148
|
-
const image = await page.objs.get(imageKey);
|
|
148
|
+
const image = imageKey.startsWith("g_") ? await page.commonObjs.get(imageKey) : await page.objs.get(imageKey);
|
|
149
149
|
if (!image || !image.data || !image.width || !image.height) {
|
|
150
150
|
continue;
|
|
151
151
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -143,7 +143,7 @@ async function extractImages$1(data, pageNumber) {
|
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
145
|
const imageKey = operatorList.argsArray[i][0];
|
|
146
|
-
const image = await page.objs.get(imageKey);
|
|
146
|
+
const image = imageKey.startsWith("g_") ? await page.commonObjs.get(imageKey) : await page.objs.get(imageKey);
|
|
147
147
|
if (!image || !image.data || !image.width || !image.height) {
|
|
148
148
|
continue;
|
|
149
149
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unpdf",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"packageManager": "pnpm@10.10.0",
|
|
6
6
|
"description": "PDF extraction and rendering across all JavaScript runtimes",
|
|
7
7
|
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@antfu/eslint-config": "^4.12.0",
|
|
74
|
-
"@napi-rs/canvas": "^0.1.
|
|
74
|
+
"@napi-rs/canvas": "^0.1.70",
|
|
75
75
|
"@rollup/plugin-alias": "^5.1.1",
|
|
76
76
|
"@rollup/plugin-inject": "^5.0.5",
|
|
77
77
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
81
81
|
"@types/node": "^22.15.3",
|
|
82
82
|
"bumpp": "^10.1.0",
|
|
83
|
-
"eslint": "^9.
|
|
83
|
+
"eslint": "^9.26.0",
|
|
84
84
|
"fast-glob": "^3.3.3",
|
|
85
85
|
"pdfjs-dist": "~5.2.133",
|
|
86
86
|
"rollup": "^4.40.1",
|