pdfium-native 0.1.7 → 0.2.2
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 +83 -39
- package/binding.gyp +27 -1
- package/dist/document.d.ts +1 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/page.d.ts +6 -6
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +1 -1
- package/dist/page.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/lib/document.ts +1 -1
- package/lib/page.ts +6 -6
- package/lib/types.ts +6 -6
- package/package.json +17 -4
- package/scripts/bundle-lib.mjs +24 -3
- package/scripts/download-pdfium.mjs +2 -1
- package/scripts/generate-fixtures.mjs +27 -0
- package/scripts/install.mjs +33 -3
- package/src/document.h +30 -79
- package/src/napi_helpers.h +2 -1
- package/src/page.h +51 -341
- package/src/page_workers.h +724 -0
- package/src/pdfium_addon.cc +6 -0
- package/lib/__tests__/document.test.ts +0 -99
- package/lib/__tests__/features.test.ts +0 -72
- package/lib/__tests__/fixtures.ts +0 -71
- package/lib/__tests__/load.test.ts +0 -68
- package/lib/__tests__/page.test.ts +0 -123
- package/lib/__tests__/render.test.ts +0 -103
- package/lib/__tests__/search.test.ts +0 -44
package/README.md
CHANGED
|
@@ -1,48 +1,92 @@
|
|
|
1
1
|
# pdfium-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/pdfium-native)
|
|
4
|
+
[](https://nodejs.org)
|
|
5
|
+
[](https://github.com/xonaman/nodejs-pdfium-native/blob/main/LICENSE)
|
|
6
|
+
[]()
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Fast, native PDF rendering and text extraction for Node.js — powered by [PDFium](https://pdfium.googlesource.com/pdfium/), the same engine used in Chromium. Built as a C++ addon with N-API for ABI stability across Node.js versions.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
> Designed for server-side workloads. Non-blocking, fast, and production-ready.
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
## 🚀 Quick Start
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { loadDocument } from 'pdfium-native';
|
|
16
|
+
|
|
17
|
+
const doc = await loadDocument('invoice.pdf');
|
|
18
|
+
const page = await doc.getPage(0);
|
|
19
|
+
|
|
20
|
+
const text = await page.getText();
|
|
21
|
+
const image = await page.render({ scale: 3, format: 'png' }); // high-resolution render
|
|
22
|
+
|
|
23
|
+
page.close();
|
|
24
|
+
doc.destroy();
|
|
11
25
|
```
|
|
12
26
|
|
|
13
|
-
|
|
27
|
+
## 💡 Why pdfium-native?
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
**⚡ Performance**
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
| macOS | arm64, x64 |
|
|
20
|
-
| Linux (glibc) | x64, arm64, arm, ppc64 |
|
|
21
|
-
| Linux (musl / Alpine) | x64, arm64 |
|
|
22
|
-
| Windows | x64, arm64 |
|
|
31
|
+
- Native C++ — no WASM overhead, no JS parsing
|
|
32
|
+
- Non-blocking — all operations run off the main thread via libuv workers
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
**🛠️ Developer experience**
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
- Built-in JPEG/PNG rendering — no extra dependencies like sharp
|
|
37
|
+
- Prebuilt binaries for 10 platform/arch combinations — no compile step
|
|
38
|
+
- Full TypeScript support with types included
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
const page = await doc.getPage(0);
|
|
40
|
+
**🔒 Reliability**
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
- Built on PDFium — the PDF engine used in Chromium
|
|
43
|
+
- ABI-stable via N-API — works across Node.js 18–24 without recompilation
|
|
44
|
+
- Password-protected PDFs supported out of the box
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
const jpeg = await page.render({ scale: 3, format: 'jpeg', quality: 90 });
|
|
46
|
+
### 🎯 Use cases
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
- 🖼️ Generate thumbnails and previews for uploaded PDFs
|
|
49
|
+
- 📄 Extract searchable text from documents at scale
|
|
50
|
+
- ⚙️ Build server-side PDF processing pipelines
|
|
51
|
+
- 🔗 Read annotations, bookmarks, and links from existing PDFs
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
### 📊 How it compares
|
|
54
|
+
|
|
55
|
+
| | **pdfium-native** | @hyzyla/pdfium | pdfjs-dist | pdf-parse | pdf2json |
|
|
56
|
+
| ------------------- | ----------------------- | ------------------------- | ----------------- | -------------- | ------------------- |
|
|
57
|
+
| Engine | PDFium (C++ addon) | PDFium (WASM) | pdf.js (JS) | pdf.js (JS) | pdf.js fork (JS) |
|
|
58
|
+
| Rendering | ✅ JPEG/PNG built-in | ⚠️ Raw bitmap (BYO sharp) | ⚠️ Canvas/browser | ❌ | ❌ |
|
|
59
|
+
| Text extraction | ✅ | ❌ | ✅ | ✅ | ✅ (structured) |
|
|
60
|
+
| Search (with rects) | ✅ | ❌ | ⚠️ Manual | ❌ | ❌ |
|
|
61
|
+
| Annotations | ✅ | ❌ | ⚠️ Partial | ❌ | ❌ |
|
|
62
|
+
| Bookmarks | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
63
|
+
| Links | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
64
|
+
| Form fields | ❌ | ❌ | ✅ | ❌ | ✅ |
|
|
65
|
+
| Async I/O | ✅ libuv workers | ❌ Sync (WASM) | ❌ Main thread | ❌ Main thread | ⚠️ Events / streams |
|
|
66
|
+
| Environment | Node.js | Node.js + browser | Node.js + browser | Node.js | Node.js |
|
|
67
|
+
| Dependencies | None¹ | None (WASM bundled) | None | pdf.js | None (since v3) |
|
|
68
|
+
| Platforms | macOS / Linux / Windows | Any (WASM) | Any | Any | Any |
|
|
69
|
+
|
|
70
|
+
¹ Prebuilt binaries downloaded at install — no runtime dependencies. Falls back to source compilation if unavailable.
|
|
71
|
+
|
|
72
|
+
## 📦 Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install pdfium-native
|
|
43
76
|
```
|
|
44
77
|
|
|
45
|
-
|
|
78
|
+
Prebuilt binaries are available for all [supported platforms](#supported-platforms) — most installs require no compiler. If no prebuilt is available, the package falls back to compiling from source (requires a C++ toolchain: Xcode CLI tools on macOS, `build-essential` on Linux, Visual Studio on Windows).
|
|
79
|
+
|
|
80
|
+
## 🌍 Supported Platforms
|
|
81
|
+
|
|
82
|
+
| OS | Architectures |
|
|
83
|
+
| --------------------- | ---------------------- |
|
|
84
|
+
| macOS | arm64, x64 |
|
|
85
|
+
| Linux (glibc) | x64, arm64, arm, ppc64 |
|
|
86
|
+
| Linux (musl / Alpine) | x64, arm64 |
|
|
87
|
+
| Windows | x64, arm64 |
|
|
88
|
+
|
|
89
|
+
## 📚 API
|
|
46
90
|
|
|
47
91
|
### `loadDocument(input, password?)`
|
|
48
92
|
|
|
@@ -73,14 +117,14 @@ Async generator that yields every page. Caller must close each page.
|
|
|
73
117
|
|
|
74
118
|
```typescript
|
|
75
119
|
for await (const page of doc.pages()) {
|
|
76
|
-
console.log(page.getText());
|
|
120
|
+
console.log(await page.getText());
|
|
77
121
|
page.close();
|
|
78
122
|
}
|
|
79
123
|
```
|
|
80
124
|
|
|
81
125
|
#### `getBookmarks()`
|
|
82
126
|
|
|
83
|
-
Returns the bookmark/outline tree
|
|
127
|
+
Returns the bookmark/outline tree. Returns `Promise<Bookmark[]>`.
|
|
84
128
|
|
|
85
129
|
```typescript
|
|
86
130
|
interface Bookmark {
|
|
@@ -108,7 +152,7 @@ Closes the document and frees all native resources. Must be called when done.
|
|
|
108
152
|
|
|
109
153
|
#### `getText()`
|
|
110
154
|
|
|
111
|
-
Extracts all text from the page
|
|
155
|
+
Extracts all text from the page. Returns `Promise<string>`.
|
|
112
156
|
|
|
113
157
|
#### `render(options?)`
|
|
114
158
|
|
|
@@ -127,7 +171,7 @@ interface PageRenderOptions {
|
|
|
127
171
|
|
|
128
172
|
#### `getObject(index)`
|
|
129
173
|
|
|
130
|
-
Returns the page object at the given index. Objects are discriminated by `type`:
|
|
174
|
+
Returns the page object at the given index. Returns `Promise<PageObject>`. Objects are discriminated by `type`:
|
|
131
175
|
|
|
132
176
|
```typescript
|
|
133
177
|
type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
|
|
@@ -144,7 +188,7 @@ type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
|
|
|
144
188
|
|
|
145
189
|
#### `getLinks()`
|
|
146
190
|
|
|
147
|
-
Returns all links on the page
|
|
191
|
+
Returns all links on the page. Returns `Promise<Link[]>`.
|
|
148
192
|
|
|
149
193
|
```typescript
|
|
150
194
|
interface Link {
|
|
@@ -156,16 +200,16 @@ interface Link {
|
|
|
156
200
|
|
|
157
201
|
#### `search(text, options?)`
|
|
158
202
|
|
|
159
|
-
Searches for text on the page. Returns
|
|
203
|
+
Searches for text on the page. Returns `Promise<SearchMatch[]>` with character positions and bounding rectangles.
|
|
160
204
|
|
|
161
205
|
```typescript
|
|
162
|
-
const matches = page.search('invoice', { caseSensitive: true, wholeWord: false });
|
|
206
|
+
const matches = await page.search('invoice', { caseSensitive: true, wholeWord: false });
|
|
163
207
|
// [{ charIndex: 42, length: 7, rects: [{ left, top, right, bottom }] }]
|
|
164
208
|
```
|
|
165
209
|
|
|
166
210
|
#### `getAnnotations()`
|
|
167
211
|
|
|
168
|
-
Returns all annotations on the page
|
|
212
|
+
Returns all annotations on the page. Returns `Promise<Annotation[]>`.
|
|
169
213
|
|
|
170
214
|
```typescript
|
|
171
215
|
interface Annotation {
|
|
@@ -200,13 +244,13 @@ interface DocumentMetadata {
|
|
|
200
244
|
|
|
201
245
|
---
|
|
202
246
|
|
|
203
|
-
## Acknowledgements
|
|
247
|
+
## 🙏 Acknowledgements
|
|
204
248
|
|
|
205
249
|
This project uses prebuilt PDFium binaries from [bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries), which provides automated builds of the PDFium library for multiple platforms. Thanks to [@bblanchon](https://github.com/bblanchon) for maintaining this invaluable resource.
|
|
206
250
|
|
|
207
|
-
## Memory Management
|
|
251
|
+
## 🧹 Memory Management
|
|
208
252
|
|
|
209
|
-
Always call `page.close()` and `doc.destroy()` when done.
|
|
253
|
+
Always call `page.close()` and `doc.destroy()` when done. While GC-triggered destructor hooks exist as a safety net, they should not be relied on — explicit cleanup ensures resources are freed promptly.
|
|
210
254
|
|
|
211
255
|
```typescript
|
|
212
256
|
const doc = await loadDocument('file.pdf');
|
|
@@ -222,6 +266,6 @@ try {
|
|
|
222
266
|
}
|
|
223
267
|
```
|
|
224
268
|
|
|
225
|
-
## License
|
|
269
|
+
## 📄 License
|
|
226
270
|
|
|
227
271
|
MIT
|
package/binding.gyp
CHANGED
|
@@ -17,11 +17,18 @@
|
|
|
17
17
|
"cflags!": [
|
|
18
18
|
"-fno-exceptions"
|
|
19
19
|
],
|
|
20
|
+
"cflags": [
|
|
21
|
+
"-Os",
|
|
22
|
+
"-flto",
|
|
23
|
+
"-ffunction-sections",
|
|
24
|
+
"-fdata-sections"
|
|
25
|
+
],
|
|
20
26
|
"cflags_cc!": [
|
|
21
27
|
"-fno-exceptions"
|
|
22
28
|
],
|
|
23
29
|
"cflags_cc": [
|
|
24
|
-
"-std=c++17"
|
|
30
|
+
"-std=c++17",
|
|
31
|
+
"-fvisibility=hidden"
|
|
25
32
|
],
|
|
26
33
|
"conditions": [
|
|
27
34
|
[
|
|
@@ -30,10 +37,21 @@
|
|
|
30
37
|
"xcode_settings": {
|
|
31
38
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
32
39
|
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
40
|
+
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
|
|
41
|
+
"DEAD_CODE_STRIPPING": "YES",
|
|
42
|
+
"LLVM_LTO": "YES",
|
|
43
|
+
"OTHER_CPLUSPLUSFLAGS": [
|
|
44
|
+
"-Os",
|
|
45
|
+
"-ffunction-sections",
|
|
46
|
+
"-fdata-sections"
|
|
47
|
+
],
|
|
33
48
|
"OTHER_LDFLAGS": [
|
|
34
49
|
"-L<(module_root_dir)/deps/pdfium/lib",
|
|
35
50
|
"-lpdfium",
|
|
36
51
|
"-Wl,-rpath,@loader_path",
|
|
52
|
+
"-Wl,-dead_strip",
|
|
53
|
+
"-Wl,-S",
|
|
54
|
+
"-flto",
|
|
37
55
|
"-framework CoreFoundation",
|
|
38
56
|
"-framework CoreGraphics"
|
|
39
57
|
]
|
|
@@ -47,6 +65,9 @@
|
|
|
47
65
|
"-L<(module_root_dir)/deps/pdfium/lib",
|
|
48
66
|
"-lpdfium",
|
|
49
67
|
"-Wl,-rpath,'$$ORIGIN'",
|
|
68
|
+
"-Wl,--gc-sections",
|
|
69
|
+
"-Wl,-S",
|
|
70
|
+
"-flto",
|
|
50
71
|
"-lpthread",
|
|
51
72
|
"-ldl"
|
|
52
73
|
]
|
|
@@ -61,9 +82,14 @@
|
|
|
61
82
|
"msvs_settings": {
|
|
62
83
|
"VCCLCompilerTool": {
|
|
63
84
|
"ExceptionHandling": 1,
|
|
85
|
+
"Optimization": 1,
|
|
86
|
+
"WholeProgramOptimization": "true",
|
|
64
87
|
"AdditionalOptions": [
|
|
65
88
|
"/std:c++17"
|
|
66
89
|
]
|
|
90
|
+
},
|
|
91
|
+
"VCLinkerTool": {
|
|
92
|
+
"LinkTimeCodeGeneration": 1
|
|
67
93
|
}
|
|
68
94
|
},
|
|
69
95
|
"libraries": [
|
package/dist/document.d.ts
CHANGED
|
@@ -18,6 +18,6 @@ export declare class PDFiumDocument {
|
|
|
18
18
|
/** Closes the document and frees all resources. */
|
|
19
19
|
destroy(): void;
|
|
20
20
|
/** Returns the bookmark/outline tree. */
|
|
21
|
-
getBookmarks(): Bookmark[]
|
|
21
|
+
getBookmarks(): Promise<Bookmark[]>;
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=document.d.ts.map
|
package/dist/document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7E;;GAEG;AACH,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,cAAc;IAK1C,oCAAoC;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,4EAA4E;IACrE,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAM1C,mDAAmD;IACnD,OAAO,IAAI,IAAI;IAIf,yCAAyC;IACzC,YAAY,IAAI,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7E;;GAEG;AACH,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,cAAc;IAK1C,oCAAoC;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,4EAA4E;IACrE,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAM1C,mDAAmD;IACnD,OAAO,IAAI,IAAI;IAIf,yCAAyC;IACzC,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;CAGpC"}
|
package/dist/page.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class PDFiumPage {
|
|
|
17
17
|
/** @internal */
|
|
18
18
|
constructor(native: NativePage);
|
|
19
19
|
/** Extracts all text from the page. */
|
|
20
|
-
getText(): string
|
|
20
|
+
getText(): Promise<string>;
|
|
21
21
|
/** Renders the page to a file. */
|
|
22
22
|
render(options: PageRenderOptions & {
|
|
23
23
|
output: string;
|
|
@@ -25,16 +25,16 @@ export declare class PDFiumPage {
|
|
|
25
25
|
/** Renders the page to an encoded image buffer (JPEG or PNG). */
|
|
26
26
|
render(options?: PageRenderOptions): Promise<Buffer>;
|
|
27
27
|
/** Returns the page object at the given index with type and bounds. */
|
|
28
|
-
getObject(index: number): PageObject
|
|
28
|
+
getObject(index: number): Promise<PageObject>;
|
|
29
29
|
/** Iterates over all page objects (text spans, paths, images, etc.). */
|
|
30
|
-
objects():
|
|
30
|
+
objects(): AsyncGenerator<PageObject>;
|
|
31
31
|
/** Closes the page and frees resources. */
|
|
32
32
|
close(): void;
|
|
33
33
|
/** Returns all links on the page. */
|
|
34
|
-
getLinks(): Link[]
|
|
34
|
+
getLinks(): Promise<Link[]>;
|
|
35
35
|
/** Searches for text on the page. Returns matches with positions and bounding rects. */
|
|
36
|
-
search(text: string, options?: SearchOptions): SearchMatch[]
|
|
36
|
+
search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
|
|
37
37
|
/** Returns all annotations on the page. */
|
|
38
|
-
getAnnotations(): Annotation[]
|
|
38
|
+
getAnnotations(): Promise<Annotation[]>;
|
|
39
39
|
}
|
|
40
40
|
//# sourceMappingURL=page.d.ts.map
|
package/dist/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,IAAI,EACJ,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,UAAU;IAaT,OAAO,CAAC,MAAM;IAZ1B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gBAAgB;gBACI,MAAM,EAAE,UAAU;IAQtC,uCAAuC;IACvC,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,IAAI,EACJ,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,UAAU;IAaT,OAAO,CAAC,MAAM;IAZ1B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gBAAgB;gBACI,MAAM,EAAE,UAAU;IAQtC,uCAAuC;IACvC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,kCAAkC;IAClC,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACtE,iEAAiE;IACjE,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKpD,uEAAuE;IACvE,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI7C,wEAAwE;IACjE,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IAM5C,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAIb,qCAAqC;IACrC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI3B,wFAAwF;IACxF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIrE,2CAA2C;IAC3C,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAGxC"}
|
package/dist/page.js
CHANGED
|
@@ -34,7 +34,7 @@ export class PDFiumPage {
|
|
|
34
34
|
return this.native.getObject(index);
|
|
35
35
|
}
|
|
36
36
|
/** Iterates over all page objects (text spans, paths, images, etc.). */
|
|
37
|
-
*objects() {
|
|
37
|
+
async *objects() {
|
|
38
38
|
for (let i = 0; i < this.objectCount; i++) {
|
|
39
39
|
yield this.getObject(i);
|
|
40
40
|
}
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,UAAU;IAaD;IAZpB,+CAA+C;IACtC,KAAK,CAAS;IACvB,gDAAgD;IACvC,MAAM,CAAS;IACxB,iCAAiC;IACxB,IAAI,CAAW;IACxB,0BA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AG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACxC,CAAC;IAED,uCAAuC;IACvC,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAMD,MAAM,CAAC,OAA2B;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,uEAAuE;IACvE,SAAS,CAAC,KAAa;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,CAAC,OAAO;QACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,qCAAqC;IACrC,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED,wFAAwF;IACxF,MAAM,CAAC,IAAY,EAAE,OAAuB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,2CAA2C;IAC3C,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -98,19 +98,19 @@ export interface NativePage {
|
|
|
98
98
|
readonly height: number;
|
|
99
99
|
readonly size: PageSize;
|
|
100
100
|
readonly objectCount: number;
|
|
101
|
-
getText(): string
|
|
101
|
+
getText(): Promise<string>;
|
|
102
102
|
render(options?: PageRenderOptions): Promise<Buffer | void>;
|
|
103
|
-
getObject(index: number): PageObject
|
|
104
|
-
getLinks(): Link[]
|
|
105
|
-
search(text: string, options?: SearchOptions): SearchMatch[]
|
|
106
|
-
getAnnotations(): Annotation[]
|
|
103
|
+
getObject(index: number): Promise<PageObject>;
|
|
104
|
+
getLinks(): Promise<Link[]>;
|
|
105
|
+
search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
|
|
106
|
+
getAnnotations(): Promise<Annotation[]>;
|
|
107
107
|
close(): void;
|
|
108
108
|
}
|
|
109
109
|
export interface NativeDocument {
|
|
110
110
|
readonly pageCount: number;
|
|
111
111
|
readonly metadata: DocumentMetadata;
|
|
112
112
|
getPage(index: number): Promise<NativePage>;
|
|
113
|
-
getBookmarks(): Bookmark[]
|
|
113
|
+
getBookmarks(): Promise<Bookmark[]>;
|
|
114
114
|
destroy(): void;
|
|
115
115
|
}
|
|
116
116
|
export interface NativeAddon {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,g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AC3B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5C,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAClF"}
|
package/lib/document.ts
CHANGED
package/lib/page.ts
CHANGED
|
@@ -34,7 +34,7 @@ export class PDFiumPage {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** Extracts all text from the page. */
|
|
37
|
-
getText(): string {
|
|
37
|
+
getText(): Promise<string> {
|
|
38
38
|
return this.native.getText();
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -47,12 +47,12 @@ export class PDFiumPage {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** Returns the page object at the given index with type and bounds. */
|
|
50
|
-
getObject(index: number): PageObject {
|
|
50
|
+
getObject(index: number): Promise<PageObject> {
|
|
51
51
|
return this.native.getObject(index);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/** Iterates over all page objects (text spans, paths, images, etc.). */
|
|
55
|
-
*objects():
|
|
55
|
+
async *objects(): AsyncGenerator<PageObject> {
|
|
56
56
|
for (let i = 0; i < this.objectCount; i++) {
|
|
57
57
|
yield this.getObject(i);
|
|
58
58
|
}
|
|
@@ -64,17 +64,17 @@ export class PDFiumPage {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/** Returns all links on the page. */
|
|
67
|
-
getLinks(): Link[] {
|
|
67
|
+
getLinks(): Promise<Link[]> {
|
|
68
68
|
return this.native.getLinks();
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/** Searches for text on the page. Returns matches with positions and bounding rects. */
|
|
72
|
-
search(text: string, options?: SearchOptions): SearchMatch[] {
|
|
72
|
+
search(text: string, options?: SearchOptions): Promise<SearchMatch[]> {
|
|
73
73
|
return this.native.search(text, options);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/** Returns all annotations on the page. */
|
|
77
|
-
getAnnotations(): Annotation[] {
|
|
77
|
+
getAnnotations(): Promise<Annotation[]> {
|
|
78
78
|
return this.native.getAnnotations();
|
|
79
79
|
}
|
|
80
80
|
}
|
package/lib/types.ts
CHANGED
|
@@ -132,12 +132,12 @@ export interface NativePage {
|
|
|
132
132
|
readonly height: number;
|
|
133
133
|
readonly size: PageSize;
|
|
134
134
|
readonly objectCount: number;
|
|
135
|
-
getText(): string
|
|
135
|
+
getText(): Promise<string>;
|
|
136
136
|
render(options?: PageRenderOptions): Promise<Buffer | void>;
|
|
137
|
-
getObject(index: number): PageObject
|
|
138
|
-
getLinks(): Link[]
|
|
139
|
-
search(text: string, options?: SearchOptions): SearchMatch[]
|
|
140
|
-
getAnnotations(): Annotation[]
|
|
137
|
+
getObject(index: number): Promise<PageObject>;
|
|
138
|
+
getLinks(): Promise<Link[]>;
|
|
139
|
+
search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
|
|
140
|
+
getAnnotations(): Promise<Annotation[]>;
|
|
141
141
|
close(): void;
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -145,7 +145,7 @@ export interface NativeDocument {
|
|
|
145
145
|
readonly pageCount: number;
|
|
146
146
|
readonly metadata: DocumentMetadata;
|
|
147
147
|
getPage(index: number): Promise<NativePage>;
|
|
148
|
-
getBookmarks(): Bookmark[]
|
|
148
|
+
getBookmarks(): Promise<Bookmark[]>;
|
|
149
149
|
destroy(): void;
|
|
150
150
|
}
|
|
151
151
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfium-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Native Node.js bindings for PDFium",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,9 +13,18 @@
|
|
|
13
13
|
"native",
|
|
14
14
|
"render",
|
|
15
15
|
"text-extraction",
|
|
16
|
-
"ocr",
|
|
17
16
|
"node-addon",
|
|
18
|
-
"napi"
|
|
17
|
+
"napi",
|
|
18
|
+
"pdf-parser",
|
|
19
|
+
"pdf-reader",
|
|
20
|
+
"pdf-to-text",
|
|
21
|
+
"pdf-to-image",
|
|
22
|
+
"pdf-render",
|
|
23
|
+
"extract-text",
|
|
24
|
+
"search",
|
|
25
|
+
"annotations",
|
|
26
|
+
"bookmarks",
|
|
27
|
+
"chromium"
|
|
19
28
|
],
|
|
20
29
|
"main": "dist/index.js",
|
|
21
30
|
"types": "dist/index.d.ts",
|
|
@@ -36,6 +45,10 @@
|
|
|
36
45
|
"type": "git",
|
|
37
46
|
"url": "git+https://github.com/xonaman/nodejs-pdfium-native.git"
|
|
38
47
|
},
|
|
48
|
+
"homepage": "https://github.com/xonaman/nodejs-pdfium-native#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/xonaman/nodejs-pdfium-native/issues"
|
|
51
|
+
},
|
|
39
52
|
"publishConfig": {
|
|
40
53
|
"access": "public"
|
|
41
54
|
},
|
|
@@ -77,4 +90,4 @@
|
|
|
77
90
|
"typescript-eslint": "^8.57.2",
|
|
78
91
|
"vitest": "^4.1.2"
|
|
79
92
|
}
|
|
80
|
-
}
|
|
93
|
+
}
|
package/scripts/bundle-lib.mjs
CHANGED
|
@@ -11,15 +11,28 @@ if (!existsSync(nodeFile)) {
|
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/** Strip debug symbols from a binary. */
|
|
15
|
+
function strip(file) {
|
|
16
|
+
// macOS: -S strips debug symbols only (preserves load commands in dylibs)
|
|
17
|
+
// Linux: -s strips all symbols
|
|
18
|
+
const args = process.platform === 'darwin' ? ['-S'] : ['-s'];
|
|
19
|
+
try {
|
|
20
|
+
execFileSync('strip', [...args, file], { stdio: 'inherit' });
|
|
21
|
+
console.log(`Stripped ${file.split('/').pop()}`);
|
|
22
|
+
} catch {
|
|
23
|
+
console.warn(`strip failed for ${file.split('/').pop()} — continuing`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
// on Windows, binding.gyp copies the DLL via "copies" — nothing else to do
|
|
15
28
|
if (process.platform === 'win32') {
|
|
16
29
|
const dll = join(outDir, 'pdfium.dll');
|
|
17
|
-
if (existsSync(dll)) {
|
|
18
|
-
console.log('pdfium.dll already in build/Release/ (copied by node-gyp).');
|
|
19
|
-
} else {
|
|
30
|
+
if (!existsSync(dll)) {
|
|
20
31
|
console.error('pdfium.dll not found in build/Release/ — check binding.gyp copies.');
|
|
21
32
|
process.exit(1);
|
|
22
33
|
}
|
|
34
|
+
console.log('pdfium.dll already in build/Release/ (copied by node-gyp).');
|
|
35
|
+
strip(nodeFile);
|
|
23
36
|
console.log('Bundle complete.');
|
|
24
37
|
process.exit(0);
|
|
25
38
|
}
|
|
@@ -63,4 +76,12 @@ if (process.platform === 'darwin') {
|
|
|
63
76
|
}
|
|
64
77
|
}
|
|
65
78
|
|
|
79
|
+
// strip debug symbols from shared libraries on Linux to reduce binary size
|
|
80
|
+
// pdfium.node is stripped at link time via -Wl,-S in binding.gyp
|
|
81
|
+
if (process.platform === 'linux') {
|
|
82
|
+
for (const lib of libs) {
|
|
83
|
+
strip(join(outDir, lib));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
66
87
|
console.log('Bundle complete.');
|
|
@@ -40,7 +40,8 @@ const TARGETS = {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const platform = process.platform;
|
|
43
|
-
|
|
43
|
+
// support cross-compilation via npm_config_arch (e.g. win32 x64 → arm64)
|
|
44
|
+
const arch = process.env.npm_config_arch || process.arch;
|
|
44
45
|
const musl = isMusl();
|
|
45
46
|
const key = musl ? `${platform}-musl-${arch}` : `${platform}-${arch}`;
|
|
46
47
|
const target = TARGETS[key];
|
|
@@ -178,12 +178,39 @@ async function createBookmarkPdf() {
|
|
|
178
178
|
return doc.save();
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
// --- Minimal single-page PDF ---
|
|
182
|
+
async function createMinimalPdf() {
|
|
183
|
+
const doc = await PDFDocument.create();
|
|
184
|
+
doc.addPage([612, 792]);
|
|
185
|
+
return doc.save();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// --- Two-page PDF with different sizes ---
|
|
189
|
+
async function createTwoPagePdf() {
|
|
190
|
+
const doc = await PDFDocument.create();
|
|
191
|
+
doc.addPage([612, 792]);
|
|
192
|
+
doc.addPage([400, 600]);
|
|
193
|
+
return doc.save();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// --- PDF with text content ---
|
|
197
|
+
async function createTextPdf() {
|
|
198
|
+
const doc = await PDFDocument.create();
|
|
199
|
+
const page = doc.addPage([612, 792]);
|
|
200
|
+
const font = await doc.embedFont(StandardFonts.Helvetica);
|
|
201
|
+
page.drawText('Hello', { x: 100, y: 700, size: 12, font });
|
|
202
|
+
return doc.save();
|
|
203
|
+
}
|
|
204
|
+
|
|
181
205
|
// Generate all fixtures
|
|
182
206
|
const fixtures = [
|
|
183
207
|
['metadata.pdf', createMetadataPdf],
|
|
184
208
|
['annotations.pdf', createAnnotationPdf],
|
|
185
209
|
['links.pdf', createLinkPdf],
|
|
186
210
|
['bookmarks.pdf', createBookmarkPdf],
|
|
211
|
+
['minimal.pdf', createMinimalPdf],
|
|
212
|
+
['two-page.pdf', createTwoPagePdf],
|
|
213
|
+
['text.pdf', createTextPdf],
|
|
187
214
|
];
|
|
188
215
|
|
|
189
216
|
for (const [name, generator] of fixtures) {
|