pdfium-native 0.4.0 → 0.5.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/CHANGELOG.md +9 -0
- package/README.md +89 -14
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/lib/index.ts +39 -1
- package/lib/types.ts +28 -0
- package/package.json +1 -1
- package/src/pdfium_addon.cc +148 -0
- package/src/split_merge_worker.h +343 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.5.0] - 2026-04-04
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `splitDocument()` — split a PDF into multiple documents at given page indices, with buffer or file output
|
|
12
|
+
- `mergeDocuments()` — combine multiple PDFs into one, supporting buffers, file paths, and per-document passwords
|
|
13
|
+
- Comparison table in README now includes Split / Merge row
|
|
14
|
+
- Table of contents in README
|
|
15
|
+
|
|
7
16
|
## [0.4.0] - 2026-04-04
|
|
8
17
|
|
|
9
18
|
### Added
|
package/README.md
CHANGED
|
@@ -48,27 +48,42 @@ doc.destroy();
|
|
|
48
48
|
- 🖼️ Generate thumbnails and previews for uploaded PDFs
|
|
49
49
|
- 📄 Extract searchable text from documents at scale
|
|
50
50
|
- ⚙️ Build server-side PDF processing pipelines
|
|
51
|
+
- ✂️ Split PDFs by page range or merge multiple PDFs into one
|
|
51
52
|
- 🔗 Read annotations, bookmarks, links, and form fields from existing PDFs
|
|
52
53
|
|
|
53
54
|
### 📊 How it compares
|
|
54
55
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
| Engine
|
|
58
|
-
| Rendering
|
|
59
|
-
| Text extraction
|
|
60
|
-
| Search
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
| Platforms | macOS / Linux / Windows | Any (WASM) | Any |
|
|
56
|
+
| | **pdfium-native** | @hyzyla/pdfium | pdfjs-dist |
|
|
57
|
+
| --------------- | -------------------- | ------------------- | ----------------- |
|
|
58
|
+
| Engine | PDFium (C++ addon) | PDFium (WASM) | pdf.js (JS) |
|
|
59
|
+
| Rendering | ✅ JPEG/PNG built-in | ⚠️ Raw bitmap (BYO) | ⚠️ Canvas/browser |
|
|
60
|
+
| Text extraction | ✅ | ❌ | ✅ |
|
|
61
|
+
| Search | ✅ With rects | ❌ | ⚠️ Manual |
|
|
62
|
+
| Split / Merge | ✅ | ❌ | ❌ |
|
|
63
|
+
| Annotations | ✅ | ❌ | ⚠️ Partial |
|
|
64
|
+
| Bookmarks | ✅ | ❌ | ✅ |
|
|
65
|
+
| Links | ✅ | ❌ | ✅ |
|
|
66
|
+
| Form fields | ✅ | ❌ | ✅ |
|
|
67
|
+
| Async I/O | ✅ libuv workers | ❌ Sync | ❌ Main thread |
|
|
68
|
+
| Platforms | macOS/Linux/Windows | Any (WASM) | Any |
|
|
69
69
|
|
|
70
70
|
¹ Prebuilt binaries downloaded at install — no runtime dependencies. Falls back to source compilation if unavailable.
|
|
71
71
|
|
|
72
|
+
## Table of Contents
|
|
73
|
+
|
|
74
|
+
- [Install](#-install)
|
|
75
|
+
- [Supported Platforms](#-supported-platforms)
|
|
76
|
+
- [API](#-api)
|
|
77
|
+
- [loadDocument](#loaddocumentinput-password)
|
|
78
|
+
- [splitDocument](#splitdocumentinput-splitat-options)
|
|
79
|
+
- [mergeDocuments](#mergedocumentsinputs-options)
|
|
80
|
+
- [PDFiumDocument](#pdfiumdocument)
|
|
81
|
+
- [PDFiumPage](#pdfiumpage)
|
|
82
|
+
- [DocumentMetadata](#documentmetadata)
|
|
83
|
+
- [Concurrency](#️-concurrency)
|
|
84
|
+
- [Memory Management](#-memory-management)
|
|
85
|
+
- [License](#-license)
|
|
86
|
+
|
|
72
87
|
## 📦 Install
|
|
73
88
|
|
|
74
89
|
```bash
|
|
@@ -100,6 +115,66 @@ const doc = await loadDocument(buffer, 'secret');
|
|
|
100
115
|
|
|
101
116
|
---
|
|
102
117
|
|
|
118
|
+
### `splitDocument(input, splitAt, options?)`
|
|
119
|
+
|
|
120
|
+
Splits a PDF into multiple documents at the given page indices. Each index in `splitAt` marks the first page of a new chunk. Returns `Promise<Buffer[]>`, or `Promise<void>` if `outputs` is set.
|
|
121
|
+
|
|
122
|
+
A 10-page PDF with `splitAt: [3, 7]` produces three documents: pages 0–2, 3–6, and 7–9.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { splitDocument } from 'pdfium-native';
|
|
126
|
+
|
|
127
|
+
// split a two-page PDF into two single-page documents
|
|
128
|
+
const [part1, part2] = await splitDocument('report.pdf', [1]);
|
|
129
|
+
|
|
130
|
+
// split into three parts (no split points = single document containing all pages)
|
|
131
|
+
const [a, b, c] = await splitDocument(buffer, [3, 7]);
|
|
132
|
+
|
|
133
|
+
// write parts to files
|
|
134
|
+
await splitDocument('report.pdf', [5], {
|
|
135
|
+
outputs: ['first-half.pdf', 'second-half.pdf'],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// password-protected source
|
|
139
|
+
const parts = await splitDocument('encrypted.pdf', [3], { password: 'secret' });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
| Option | Type | Default | Description |
|
|
143
|
+
| ---------- | ---------- | ------- | --------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `outputs` | `string[]` | — | Write each part to these file paths instead of returning Buffers. Must have `splitAt.length + 1` entries. |
|
|
145
|
+
| `password` | `string` | — | Password for the source PDF. |
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
### `mergeDocuments(inputs, options?)`
|
|
150
|
+
|
|
151
|
+
Combines multiple PDFs into a single document. Returns `Promise<Buffer>`, or `Promise<void>` if `output` is set.
|
|
152
|
+
|
|
153
|
+
Each element of `inputs` can be a `Buffer`, a file path string, or an object `{ input, password? }` for password-protected PDFs.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { mergeDocuments } from 'pdfium-native';
|
|
157
|
+
|
|
158
|
+
// merge two files
|
|
159
|
+
const buf = await mergeDocuments(['part1.pdf', 'part2.pdf']);
|
|
160
|
+
|
|
161
|
+
// mix buffers, paths, and password-protected PDFs
|
|
162
|
+
const buf = await mergeDocuments([
|
|
163
|
+
buffer1,
|
|
164
|
+
'part2.pdf',
|
|
165
|
+
{ input: 'encrypted.pdf', password: 'secret' },
|
|
166
|
+
]);
|
|
167
|
+
|
|
168
|
+
// write directly to a file
|
|
169
|
+
await mergeDocuments(['a.pdf', 'b.pdf'], { output: 'merged.pdf' });
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
| Option | Type | Default | Description |
|
|
173
|
+
| -------- | -------- | ------- | ------------------------------------------------------ |
|
|
174
|
+
| `output` | `string` | — | Write to this file path instead of returning a Buffer. |
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
103
178
|
### PDFiumDocument
|
|
104
179
|
|
|
105
180
|
| Property | Type | Description |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { PDFiumDocument } from './document.js';
|
|
2
|
+
import type { MergeDocumentInput, MergeDocumentsOptions, SplitDocumentOptions } from './types.js';
|
|
2
3
|
type PdfInput = Buffer | string;
|
|
3
4
|
/**
|
|
4
5
|
* Opens a PDF document from a Buffer or file path.
|
|
5
6
|
*/
|
|
6
7
|
export declare function loadDocument(input: PdfInput, password?: string): Promise<PDFiumDocument>;
|
|
8
|
+
/**
|
|
9
|
+
* Splits a PDF into multiple documents at the given page indices.
|
|
10
|
+
* Each index marks the first page of a new chunk.
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitDocument(input: PdfInput, splitAt: number[], options?: SplitDocumentOptions): Promise<Buffer[] | void>;
|
|
13
|
+
/**
|
|
14
|
+
* Combines multiple PDFs into a single document.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mergeDocuments(inputs: Array<PdfInput | MergeDocumentInput>, options?: MergeDocumentsOptions): Promise<Buffer | void>;
|
|
7
17
|
export { concurrency } from './concurrency.js';
|
|
8
18
|
export { PDFiumDocument } from './document.js';
|
|
9
19
|
export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
|
|
10
20
|
export { PDFiumPage } from './page.js';
|
|
11
|
-
export type { Annotation, AnnotationBorder, AnnotationType, Bookmark, DocumentMetadata, DocumentPermissions, FormField, FormFieldOption, FormFieldType, ImageColorspace, ImagePageObject, ImageRenderOptions, Link, LinkActionType, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, TextPageObject, TextRenderMode, } from './types.js';
|
|
21
|
+
export type { Annotation, AnnotationBorder, AnnotationType, Bookmark, DocumentMetadata, DocumentPermissions, FormField, FormFieldOption, FormFieldType, ImageColorspace, ImagePageObject, ImageRenderOptions, Link, LinkActionType, MergeDocumentInput, MergeDocumentsOptions, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, SplitDocumentOptions, TextPageObject, TextRenderMode, } from './types.js';
|
|
12
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAIA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ACpB,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,29 @@ export async function loadDocument(input, password) {
|
|
|
28
28
|
throw parseNativeError(err);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Splits a PDF into multiple documents at the given page indices.
|
|
33
|
+
* Each index marks the first page of a new chunk.
|
|
34
|
+
*/
|
|
35
|
+
export async function splitDocument(input, splitAt, options) {
|
|
36
|
+
try {
|
|
37
|
+
return await withConcurrency(() => addon.splitDocument(input, splitAt, options));
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
throw parseNativeError(err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Combines multiple PDFs into a single document.
|
|
45
|
+
*/
|
|
46
|
+
export async function mergeDocuments(inputs, options) {
|
|
47
|
+
try {
|
|
48
|
+
return await withConcurrency(() => addon.mergeDocuments(inputs, options));
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
throw parseNativeError(err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
31
54
|
export { concurrency } from './concurrency.js';
|
|
32
55
|
export { PDFiumDocument } from './document.js';
|
|
33
56
|
export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/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destroy(): void;
|
|
338
338
|
}
|
|
339
|
+
export interface SplitDocumentOptions {
|
|
340
|
+
/** Write each part to these file paths instead of returning Buffers. Must have splitAt.length + 1 entries. */
|
|
341
|
+
outputs?: string[];
|
|
342
|
+
/** Password for the source PDF (if encrypted). */
|
|
343
|
+
password?: string;
|
|
344
|
+
}
|
|
345
|
+
export interface MergeDocumentInput {
|
|
346
|
+
/** PDF file path or Buffer. */
|
|
347
|
+
input: Buffer | string;
|
|
348
|
+
/** Password for this PDF (if encrypted). */
|
|
349
|
+
password?: string;
|
|
350
|
+
}
|
|
351
|
+
export interface MergeDocumentsOptions {
|
|
352
|
+
/** Write to this file path instead of returning a Buffer. */
|
|
353
|
+
output?: string;
|
|
354
|
+
}
|
|
339
355
|
export interface NativeAddon {
|
|
340
356
|
loadDocument(input: Buffer | string, password?: string): Promise<NativeDocument>;
|
|
357
|
+
splitDocument(input: Buffer | string, splitAt: number[], options?: {
|
|
358
|
+
outputs?: string[];
|
|
359
|
+
password?: string;
|
|
360
|
+
}): Promise<Buffer[] | undefined>;
|
|
361
|
+
mergeDocuments(inputs: Array<Buffer | string | {
|
|
362
|
+
input: Buffer | string;
|
|
363
|
+
password?: string;
|
|
364
|
+
}>, options?: {
|
|
365
|
+
output?: string;
|
|
366
|
+
}): Promise<Buffer | undefined>;
|
|
341
367
|
}
|
|
342
368
|
export {};
|
|
343
369
|
//# sourceMappingURL=types.d.ts.map
|
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,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,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,GAAG,KAA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E,MAAM,GAAG,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,EAC9E,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAChC"}
|
package/lib/index.ts
CHANGED
|
@@ -4,7 +4,12 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
import { withConcurrency } from './concurrency.js';
|
|
5
5
|
import { PDFiumDocument } from './document.js';
|
|
6
6
|
import { parseNativeError } from './errors.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
MergeDocumentInput,
|
|
9
|
+
MergeDocumentsOptions,
|
|
10
|
+
NativeAddon,
|
|
11
|
+
SplitDocumentOptions,
|
|
12
|
+
} from './types.js';
|
|
8
13
|
|
|
9
14
|
const require = createRequire(import.meta.url);
|
|
10
15
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -34,6 +39,36 @@ export async function loadDocument(input: PdfInput, password?: string): Promise<
|
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Splits a PDF into multiple documents at the given page indices.
|
|
44
|
+
* Each index marks the first page of a new chunk.
|
|
45
|
+
*/
|
|
46
|
+
export async function splitDocument(
|
|
47
|
+
input: PdfInput,
|
|
48
|
+
splitAt: number[],
|
|
49
|
+
options?: SplitDocumentOptions,
|
|
50
|
+
): Promise<Buffer[] | void> {
|
|
51
|
+
try {
|
|
52
|
+
return await withConcurrency(() => addon.splitDocument(input, splitAt, options));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
throw parseNativeError(err);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Combines multiple PDFs into a single document.
|
|
60
|
+
*/
|
|
61
|
+
export async function mergeDocuments(
|
|
62
|
+
inputs: Array<PdfInput | MergeDocumentInput>,
|
|
63
|
+
options?: MergeDocumentsOptions,
|
|
64
|
+
): Promise<Buffer | void> {
|
|
65
|
+
try {
|
|
66
|
+
return await withConcurrency(() => addon.mergeDocuments(inputs, options));
|
|
67
|
+
} catch (err) {
|
|
68
|
+
throw parseNativeError(err);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
37
72
|
export { concurrency } from './concurrency.js';
|
|
38
73
|
export { PDFiumDocument } from './document.js';
|
|
39
74
|
export {
|
|
@@ -59,6 +94,8 @@ export type {
|
|
|
59
94
|
ImageRenderOptions,
|
|
60
95
|
Link,
|
|
61
96
|
LinkActionType,
|
|
97
|
+
MergeDocumentInput,
|
|
98
|
+
MergeDocumentsOptions,
|
|
62
99
|
OtherPageObject,
|
|
63
100
|
PageObject,
|
|
64
101
|
PageObjectBounds,
|
|
@@ -68,6 +105,7 @@ export type {
|
|
|
68
105
|
SearchMatch,
|
|
69
106
|
SearchOptions,
|
|
70
107
|
SearchRect,
|
|
108
|
+
SplitDocumentOptions,
|
|
71
109
|
TextPageObject,
|
|
72
110
|
TextRenderMode,
|
|
73
111
|
} from './types.js';
|
package/lib/types.ts
CHANGED
|
@@ -414,6 +414,34 @@ export interface NativeDocument {
|
|
|
414
414
|
destroy(): void;
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
+
export interface SplitDocumentOptions {
|
|
418
|
+
/** Write each part to these file paths instead of returning Buffers. Must have splitAt.length + 1 entries. */
|
|
419
|
+
outputs?: string[];
|
|
420
|
+
/** Password for the source PDF (if encrypted). */
|
|
421
|
+
password?: string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface MergeDocumentInput {
|
|
425
|
+
/** PDF file path or Buffer. */
|
|
426
|
+
input: Buffer | string;
|
|
427
|
+
/** Password for this PDF (if encrypted). */
|
|
428
|
+
password?: string;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export interface MergeDocumentsOptions {
|
|
432
|
+
/** Write to this file path instead of returning a Buffer. */
|
|
433
|
+
output?: string;
|
|
434
|
+
}
|
|
435
|
+
|
|
417
436
|
export interface NativeAddon {
|
|
418
437
|
loadDocument(input: Buffer | string, password?: string): Promise<NativeDocument>;
|
|
438
|
+
splitDocument(
|
|
439
|
+
input: Buffer | string,
|
|
440
|
+
splitAt: number[],
|
|
441
|
+
options?: { outputs?: string[]; password?: string },
|
|
442
|
+
): Promise<Buffer[] | undefined>;
|
|
443
|
+
mergeDocuments(
|
|
444
|
+
inputs: Array<Buffer | string | { input: Buffer | string; password?: string }>,
|
|
445
|
+
options?: { output?: string },
|
|
446
|
+
): Promise<Buffer | undefined>;
|
|
419
447
|
}
|
package/package.json
CHANGED
package/src/pdfium_addon.cc
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "fpdf_attachment.h"
|
|
6
6
|
#include "fpdf_catalog.h"
|
|
7
7
|
#include "fpdf_signature.h"
|
|
8
|
+
#include "split_merge_worker.h"
|
|
8
9
|
|
|
9
10
|
Napi::FunctionReference PDFiumDocument::pageConstructor;
|
|
10
11
|
|
|
@@ -265,6 +266,151 @@ Napi::Value LoadDocument(const Napi::CallbackInfo &info) {
|
|
|
265
266
|
return promise;
|
|
266
267
|
}
|
|
267
268
|
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
// splitDocument — split a PDF into multiple documents (async)
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
|
|
273
|
+
Napi::Value SplitDocument(const Napi::CallbackInfo &info) {
|
|
274
|
+
Napi::Env env = info.Env();
|
|
275
|
+
|
|
276
|
+
if (info.Length() < 2) {
|
|
277
|
+
Napi::TypeError::New(env, "Expected (input, splitAt, options?) arguments")
|
|
278
|
+
.ThrowAsJavaScriptException();
|
|
279
|
+
return env.Null();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
Napi::Value arg = info[0];
|
|
283
|
+
Napi::Array jsSplitAt = info[1].As<Napi::Array>();
|
|
284
|
+
|
|
285
|
+
std::vector<int> splitAt;
|
|
286
|
+
splitAt.reserve(jsSplitAt.Length());
|
|
287
|
+
for (uint32_t i = 0; i < jsSplitAt.Length(); i++) {
|
|
288
|
+
splitAt.push_back(jsSplitAt.Get(i).As<Napi::Number>().Int32Value());
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
std::vector<std::string> outputPaths;
|
|
292
|
+
std::string password;
|
|
293
|
+
if (info.Length() > 2 && info[2].IsObject()) {
|
|
294
|
+
Napi::Object opts = info[2].As<Napi::Object>();
|
|
295
|
+
if (opts.Has("outputs") && opts.Get("outputs").IsArray()) {
|
|
296
|
+
Napi::Array jsOutputs = opts.Get("outputs").As<Napi::Array>();
|
|
297
|
+
outputPaths.reserve(jsOutputs.Length());
|
|
298
|
+
for (uint32_t i = 0; i < jsOutputs.Length(); i++) {
|
|
299
|
+
outputPaths.push_back(jsOutputs.Get(i).As<Napi::String>().Utf8Value());
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (opts.Has("password") && opts.Get("password").IsString()) {
|
|
303
|
+
password = opts.Get("password").As<Napi::String>().Utf8Value();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
SplitDocumentWorker *worker = nullptr;
|
|
308
|
+
|
|
309
|
+
if (arg.IsBuffer()) {
|
|
310
|
+
auto buffer = arg.As<Napi::Buffer<uint8_t>>();
|
|
311
|
+
std::vector<uint8_t> data(buffer.Data(), buffer.Data() + buffer.Length());
|
|
312
|
+
worker =
|
|
313
|
+
new SplitDocumentWorker(env, std::move(data), std::move(splitAt),
|
|
314
|
+
std::move(outputPaths), std::move(password));
|
|
315
|
+
} else if (arg.IsString()) {
|
|
316
|
+
std::string path = arg.As<Napi::String>().Utf8Value();
|
|
317
|
+
worker =
|
|
318
|
+
new SplitDocumentWorker(env, std::move(path), std::move(splitAt),
|
|
319
|
+
std::move(outputPaths), std::move(password));
|
|
320
|
+
} else {
|
|
321
|
+
Napi::TypeError::New(env, "Expected a Buffer or string path argument")
|
|
322
|
+
.ThrowAsJavaScriptException();
|
|
323
|
+
return env.Null();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
auto promise = worker->Promise();
|
|
327
|
+
worker->Queue();
|
|
328
|
+
return promise;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ---------------------------------------------------------------------------
|
|
332
|
+
// mergeDocuments — combine multiple PDFs (async)
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
|
|
335
|
+
Napi::Value MergeDocuments(const Napi::CallbackInfo &info) {
|
|
336
|
+
Napi::Env env = info.Env();
|
|
337
|
+
|
|
338
|
+
if (info.Length() < 1 || !info[0].IsArray()) {
|
|
339
|
+
Napi::TypeError::New(env, "Expected (inputs[], options?) arguments")
|
|
340
|
+
.ThrowAsJavaScriptException();
|
|
341
|
+
return env.Null();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
Napi::Array jsInputs = info[0].As<Napi::Array>();
|
|
345
|
+
if (jsInputs.Length() == 0) {
|
|
346
|
+
Napi::TypeError::New(env, "At least one input document is required")
|
|
347
|
+
.ThrowAsJavaScriptException();
|
|
348
|
+
return env.Null();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
std::string outputPath;
|
|
352
|
+
if (info.Length() > 1 && info[1].IsObject()) {
|
|
353
|
+
Napi::Object opts = info[1].As<Napi::Object>();
|
|
354
|
+
if (opts.Has("output") && opts.Get("output").IsString()) {
|
|
355
|
+
outputPath = opts.Get("output").As<Napi::String>().Utf8Value();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
std::vector<DocInput> inputs;
|
|
360
|
+
inputs.reserve(jsInputs.Length());
|
|
361
|
+
|
|
362
|
+
for (uint32_t i = 0; i < jsInputs.Length(); i++) {
|
|
363
|
+
Napi::Value item = jsInputs.Get(i);
|
|
364
|
+
DocInput di;
|
|
365
|
+
|
|
366
|
+
// each item is either a Buffer/string, or { input, password }
|
|
367
|
+
if (item.IsBuffer()) {
|
|
368
|
+
auto buffer = item.As<Napi::Buffer<uint8_t>>();
|
|
369
|
+
di.bufferData.assign(buffer.Data(), buffer.Data() + buffer.Length());
|
|
370
|
+
di.useFile = false;
|
|
371
|
+
} else if (item.IsString()) {
|
|
372
|
+
di.filePath = item.As<Napi::String>().Utf8Value();
|
|
373
|
+
di.useFile = true;
|
|
374
|
+
} else if (item.IsObject()) {
|
|
375
|
+
Napi::Object obj = item.As<Napi::Object>();
|
|
376
|
+
if (!obj.Has("input")) {
|
|
377
|
+
Napi::TypeError::New(env, "Each input must have an 'input' property")
|
|
378
|
+
.ThrowAsJavaScriptException();
|
|
379
|
+
return env.Null();
|
|
380
|
+
}
|
|
381
|
+
Napi::Value inp = obj.Get("input");
|
|
382
|
+
if (inp.IsBuffer()) {
|
|
383
|
+
auto buffer = inp.As<Napi::Buffer<uint8_t>>();
|
|
384
|
+
di.bufferData.assign(buffer.Data(), buffer.Data() + buffer.Length());
|
|
385
|
+
di.useFile = false;
|
|
386
|
+
} else if (inp.IsString()) {
|
|
387
|
+
di.filePath = inp.As<Napi::String>().Utf8Value();
|
|
388
|
+
di.useFile = true;
|
|
389
|
+
} else {
|
|
390
|
+
Napi::TypeError::New(env, "input must be a Buffer or string path")
|
|
391
|
+
.ThrowAsJavaScriptException();
|
|
392
|
+
return env.Null();
|
|
393
|
+
}
|
|
394
|
+
if (obj.Has("password") && obj.Get("password").IsString()) {
|
|
395
|
+
di.password = obj.Get("password").As<Napi::String>().Utf8Value();
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
Napi::TypeError::New(env,
|
|
399
|
+
"Each input must be a Buffer, string, or object")
|
|
400
|
+
.ThrowAsJavaScriptException();
|
|
401
|
+
return env.Null();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
inputs.push_back(std::move(di));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
auto *worker =
|
|
408
|
+
new MergeDocumentsWorker(env, std::move(inputs), std::move(outputPath));
|
|
409
|
+
auto promise = worker->Promise();
|
|
410
|
+
worker->Queue();
|
|
411
|
+
return promise;
|
|
412
|
+
}
|
|
413
|
+
|
|
268
414
|
// ---------------------------------------------------------------------------
|
|
269
415
|
// Module init
|
|
270
416
|
// ---------------------------------------------------------------------------
|
|
@@ -293,6 +439,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
293
439
|
exports.Set("PDFiumDocument", docCtor);
|
|
294
440
|
exports.Set("PDFiumPage", pageCtor);
|
|
295
441
|
exports.Set("loadDocument", Napi::Function::New(env, LoadDocument));
|
|
442
|
+
exports.Set("splitDocument", Napi::Function::New(env, SplitDocument));
|
|
443
|
+
exports.Set("mergeDocuments", Napi::Function::New(env, MergeDocuments));
|
|
296
444
|
|
|
297
445
|
return exports;
|
|
298
446
|
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "napi_helpers.h"
|
|
4
|
+
|
|
5
|
+
#include <climits>
|
|
6
|
+
#include <cstdio>
|
|
7
|
+
#include <filesystem>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
#include "fpdf_edit.h"
|
|
11
|
+
#include "fpdf_ppo.h"
|
|
12
|
+
#include "fpdf_save.h"
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// FPDF_FILEWRITE adapter — collects saved PDF bytes into a std::vector
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
struct VectorFileWrite : FPDF_FILEWRITE {
|
|
19
|
+
std::vector<uint8_t> data;
|
|
20
|
+
|
|
21
|
+
VectorFileWrite() {
|
|
22
|
+
version = 1;
|
|
23
|
+
WriteBlock = [](FPDF_FILEWRITE_ *self, const void *buf,
|
|
24
|
+
unsigned long size) -> int {
|
|
25
|
+
auto *w = static_cast<VectorFileWrite *>(self);
|
|
26
|
+
auto *bytes = static_cast<const uint8_t *>(buf);
|
|
27
|
+
w->data.insert(w->data.end(), bytes, bytes + size);
|
|
28
|
+
return 1;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// helper: save a document to buffer or file, returning the buffer data
|
|
34
|
+
static inline bool SaveDocument(FPDF_DOCUMENT doc,
|
|
35
|
+
const std::string &outputPath,
|
|
36
|
+
std::vector<uint8_t> &outData,
|
|
37
|
+
std::string &outError) {
|
|
38
|
+
VectorFileWrite writer;
|
|
39
|
+
if (!FPDF_SaveAsCopy(doc, &writer, 0)) {
|
|
40
|
+
outError = "Failed to save PDF document";
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!outputPath.empty()) {
|
|
45
|
+
std::filesystem::path outPath(outputPath);
|
|
46
|
+
auto parentDir = outPath.parent_path();
|
|
47
|
+
if (!parentDir.empty() && !std::filesystem::is_directory(parentDir)) {
|
|
48
|
+
outError = "Parent directory does not exist: " + parentDir.string();
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
FILE *f = fopen(outputPath.c_str(), "wb");
|
|
52
|
+
if (!f) {
|
|
53
|
+
outError = "Failed to open output file: " + outputPath;
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
size_t written = fwrite(writer.data.data(), 1, writer.data.size(), f);
|
|
57
|
+
fclose(f);
|
|
58
|
+
if (written != writer.data.size()) {
|
|
59
|
+
outError = "Failed to write output file: " + outputPath;
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
outData = std::move(writer.data);
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// helper: load a document from buffer or file path
|
|
69
|
+
static inline FPDF_DOCUMENT LoadDoc(const std::vector<uint8_t> &bufferData,
|
|
70
|
+
const std::string &filePath, bool useFile,
|
|
71
|
+
const std::string &password,
|
|
72
|
+
std::string &outError) {
|
|
73
|
+
const char *pw = password.empty() ? nullptr : password.c_str();
|
|
74
|
+
FPDF_DOCUMENT doc;
|
|
75
|
+
|
|
76
|
+
if (useFile) {
|
|
77
|
+
doc = FPDF_LoadDocument(filePath.c_str(), pw);
|
|
78
|
+
} else {
|
|
79
|
+
if (bufferData.size() > static_cast<size_t>(INT_MAX)) {
|
|
80
|
+
outError = "FORMAT:Buffer too large";
|
|
81
|
+
return nullptr;
|
|
82
|
+
}
|
|
83
|
+
doc = FPDF_LoadMemDocument(bufferData.data(),
|
|
84
|
+
static_cast<int>(bufferData.size()), pw);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!doc) {
|
|
88
|
+
unsigned long err = FPDF_GetLastError();
|
|
89
|
+
switch (err) {
|
|
90
|
+
case FPDF_ERR_FILE:
|
|
91
|
+
outError = "FILE:File not found or could not be opened";
|
|
92
|
+
break;
|
|
93
|
+
case FPDF_ERR_FORMAT:
|
|
94
|
+
outError = "FORMAT:Not a valid PDF or corrupted";
|
|
95
|
+
break;
|
|
96
|
+
case FPDF_ERR_PASSWORD:
|
|
97
|
+
outError = "PASSWORD:Password required or incorrect";
|
|
98
|
+
break;
|
|
99
|
+
case FPDF_ERR_SECURITY:
|
|
100
|
+
outError = "SECURITY:Unsupported security scheme";
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
outError = "UNKNOWN:Unknown error";
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return doc;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// SplitDocumentWorker — split a PDF into multiple documents at given indices
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
class SplitDocumentWorker : public Napi::AsyncWorker {
|
|
115
|
+
public:
|
|
116
|
+
// buffer variant
|
|
117
|
+
SplitDocumentWorker(Napi::Env env, std::vector<uint8_t> data,
|
|
118
|
+
std::vector<int> splitAt,
|
|
119
|
+
std::vector<std::string> outputPaths,
|
|
120
|
+
std::string password)
|
|
121
|
+
: Napi::AsyncWorker(env), deferred_(Napi::Promise::Deferred::New(env)),
|
|
122
|
+
bufferData_(std::move(data)), splitAt_(std::move(splitAt)),
|
|
123
|
+
outputPaths_(std::move(outputPaths)), password_(std::move(password)),
|
|
124
|
+
useFile_(false) {}
|
|
125
|
+
|
|
126
|
+
// file path variant
|
|
127
|
+
SplitDocumentWorker(Napi::Env env, std::string filePath,
|
|
128
|
+
std::vector<int> splitAt,
|
|
129
|
+
std::vector<std::string> outputPaths,
|
|
130
|
+
std::string password)
|
|
131
|
+
: Napi::AsyncWorker(env), deferred_(Napi::Promise::Deferred::New(env)),
|
|
132
|
+
filePath_(std::move(filePath)), splitAt_(std::move(splitAt)),
|
|
133
|
+
outputPaths_(std::move(outputPaths)), password_(std::move(password)),
|
|
134
|
+
useFile_(true) {}
|
|
135
|
+
|
|
136
|
+
Napi::Promise Promise() { return deferred_.Promise(); }
|
|
137
|
+
|
|
138
|
+
protected:
|
|
139
|
+
void Execute() override {
|
|
140
|
+
std::lock_guard<std::mutex> lock(g_pdfium_mutex);
|
|
141
|
+
|
|
142
|
+
std::string loadError;
|
|
143
|
+
FPDF_DOCUMENT srcDoc =
|
|
144
|
+
LoadDoc(bufferData_, filePath_, useFile_, password_, loadError);
|
|
145
|
+
if (!srcDoc) {
|
|
146
|
+
SetError(loadError);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
int pageCount = FPDF_GetPageCount(srcDoc);
|
|
151
|
+
|
|
152
|
+
// validate split points are sorted, in range, and unique
|
|
153
|
+
for (size_t i = 0; i < splitAt_.size(); i++) {
|
|
154
|
+
int idx = splitAt_[i];
|
|
155
|
+
if (idx <= 0 || idx >= pageCount) {
|
|
156
|
+
FPDF_CloseDocument(srcDoc);
|
|
157
|
+
SetError("Split index out of range: " + std::to_string(idx));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (i > 0 && idx <= splitAt_[i - 1]) {
|
|
161
|
+
FPDF_CloseDocument(srcDoc);
|
|
162
|
+
SetError("Split indices must be sorted in ascending order");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// build page ranges: [0, splitAt[0]), [splitAt[0], splitAt[1]), ...,
|
|
168
|
+
// [splitAt[n-1], pageCount)
|
|
169
|
+
size_t numParts = splitAt_.size() + 1;
|
|
170
|
+
resultParts_.resize(numParts);
|
|
171
|
+
|
|
172
|
+
for (size_t part = 0; part < numParts; part++) {
|
|
173
|
+
int startPage = (part == 0) ? 0 : splitAt_[part - 1];
|
|
174
|
+
int endPage = (part == splitAt_.size()) ? pageCount : splitAt_[part];
|
|
175
|
+
|
|
176
|
+
std::vector<int> indices;
|
|
177
|
+
indices.reserve(endPage - startPage);
|
|
178
|
+
for (int p = startPage; p < endPage; p++) {
|
|
179
|
+
indices.push_back(p);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
FPDF_DOCUMENT destDoc = FPDF_CreateNewDocument();
|
|
183
|
+
if (!destDoc) {
|
|
184
|
+
FPDF_CloseDocument(srcDoc);
|
|
185
|
+
SetError("Failed to create new PDF document");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
FPDF_BOOL ok = FPDF_ImportPagesByIndex(
|
|
190
|
+
destDoc, srcDoc, indices.data(),
|
|
191
|
+
static_cast<unsigned long>(indices.size()), 0);
|
|
192
|
+
if (!ok) {
|
|
193
|
+
FPDF_CloseDocument(destDoc);
|
|
194
|
+
FPDF_CloseDocument(srcDoc);
|
|
195
|
+
SetError("Failed to import pages for part " + std::to_string(part));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
std::string outPath =
|
|
200
|
+
(part < outputPaths_.size()) ? outputPaths_[part] : "";
|
|
201
|
+
std::string saveError;
|
|
202
|
+
if (!SaveDocument(destDoc, outPath, resultParts_[part], saveError)) {
|
|
203
|
+
FPDF_CloseDocument(destDoc);
|
|
204
|
+
FPDF_CloseDocument(srcDoc);
|
|
205
|
+
SetError(saveError);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
FPDF_CloseDocument(destDoc);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
FPDF_CloseDocument(srcDoc);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void OnOK() override {
|
|
216
|
+
Napi::Env env = Env();
|
|
217
|
+
if (!outputPaths_.empty()) {
|
|
218
|
+
deferred_.Resolve(env.Undefined());
|
|
219
|
+
} else {
|
|
220
|
+
Napi::Array arr = Napi::Array::New(env, resultParts_.size());
|
|
221
|
+
for (size_t i = 0; i < resultParts_.size(); i++) {
|
|
222
|
+
arr.Set(static_cast<uint32_t>(i),
|
|
223
|
+
Napi::Buffer<uint8_t>::Copy(env, resultParts_[i].data(),
|
|
224
|
+
resultParts_[i].size()));
|
|
225
|
+
}
|
|
226
|
+
deferred_.Resolve(arr);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
void OnError(const Napi::Error &err) override {
|
|
231
|
+
deferred_.Reject(err.Value());
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private:
|
|
235
|
+
Napi::Promise::Deferred deferred_;
|
|
236
|
+
std::vector<uint8_t> bufferData_;
|
|
237
|
+
std::string filePath_;
|
|
238
|
+
std::vector<int> splitAt_;
|
|
239
|
+
std::vector<std::string> outputPaths_;
|
|
240
|
+
std::string password_;
|
|
241
|
+
bool useFile_;
|
|
242
|
+
std::vector<std::vector<uint8_t>> resultParts_;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// MergeDocumentsWorker — combine multiple PDFs into one
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
|
|
249
|
+
struct DocInput {
|
|
250
|
+
std::vector<uint8_t> bufferData;
|
|
251
|
+
std::string filePath;
|
|
252
|
+
std::string password;
|
|
253
|
+
bool useFile;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
class MergeDocumentsWorker : public Napi::AsyncWorker {
|
|
257
|
+
public:
|
|
258
|
+
MergeDocumentsWorker(Napi::Env env, std::vector<DocInput> inputs,
|
|
259
|
+
std::string outputPath)
|
|
260
|
+
: Napi::AsyncWorker(env), deferred_(Napi::Promise::Deferred::New(env)),
|
|
261
|
+
inputs_(std::move(inputs)), outputPath_(std::move(outputPath)) {}
|
|
262
|
+
|
|
263
|
+
Napi::Promise Promise() { return deferred_.Promise(); }
|
|
264
|
+
|
|
265
|
+
protected:
|
|
266
|
+
void Execute() override {
|
|
267
|
+
std::lock_guard<std::mutex> lock(g_pdfium_mutex);
|
|
268
|
+
|
|
269
|
+
FPDF_DOCUMENT destDoc = FPDF_CreateNewDocument();
|
|
270
|
+
if (!destDoc) {
|
|
271
|
+
SetError("Failed to create new PDF document");
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
std::vector<FPDF_DOCUMENT> srcDocs;
|
|
276
|
+
int insertIndex = 0;
|
|
277
|
+
|
|
278
|
+
for (size_t i = 0; i < inputs_.size(); i++) {
|
|
279
|
+
auto &input = inputs_[i];
|
|
280
|
+
std::string loadError;
|
|
281
|
+
FPDF_DOCUMENT srcDoc = LoadDoc(input.bufferData, input.filePath,
|
|
282
|
+
input.useFile, input.password, loadError);
|
|
283
|
+
if (!srcDoc) {
|
|
284
|
+
// clean up already-opened docs
|
|
285
|
+
for (auto *d : srcDocs)
|
|
286
|
+
FPDF_CloseDocument(d);
|
|
287
|
+
FPDF_CloseDocument(destDoc);
|
|
288
|
+
SetError("Failed to load document " + std::to_string(i) + ": " +
|
|
289
|
+
loadError);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
srcDocs.push_back(srcDoc);
|
|
293
|
+
|
|
294
|
+
int pageCount = FPDF_GetPageCount(srcDoc);
|
|
295
|
+
|
|
296
|
+
// import all pages from this source
|
|
297
|
+
FPDF_BOOL ok =
|
|
298
|
+
FPDF_ImportPagesByIndex(destDoc, srcDoc, nullptr, 0, insertIndex);
|
|
299
|
+
if (!ok) {
|
|
300
|
+
for (auto *d : srcDocs)
|
|
301
|
+
FPDF_CloseDocument(d);
|
|
302
|
+
FPDF_CloseDocument(destDoc);
|
|
303
|
+
SetError("Failed to import pages from document " + std::to_string(i));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
insertIndex += pageCount;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
std::string saveError;
|
|
311
|
+
if (!SaveDocument(destDoc, outputPath_, resultData_, saveError)) {
|
|
312
|
+
for (auto *d : srcDocs)
|
|
313
|
+
FPDF_CloseDocument(d);
|
|
314
|
+
FPDF_CloseDocument(destDoc);
|
|
315
|
+
SetError(saveError);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
for (auto *d : srcDocs)
|
|
320
|
+
FPDF_CloseDocument(d);
|
|
321
|
+
FPDF_CloseDocument(destDoc);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
void OnOK() override {
|
|
325
|
+
Napi::Env env = Env();
|
|
326
|
+
if (outputPath_.empty()) {
|
|
327
|
+
deferred_.Resolve(Napi::Buffer<uint8_t>::Copy(env, resultData_.data(),
|
|
328
|
+
resultData_.size()));
|
|
329
|
+
} else {
|
|
330
|
+
deferred_.Resolve(env.Undefined());
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
void OnError(const Napi::Error &err) override {
|
|
335
|
+
deferred_.Reject(err.Value());
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private:
|
|
339
|
+
Napi::Promise::Deferred deferred_;
|
|
340
|
+
std::vector<DocInput> inputs_;
|
|
341
|
+
std::string outputPath_;
|
|
342
|
+
std::vector<uint8_t> resultData_;
|
|
343
|
+
};
|