pdfium-native 0.8.0 → 0.9.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.
- package/CHANGELOG.md +46 -1
- package/README.md +302 -3
- package/dist/document.d.ts +43 -2
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +41 -0
- package/dist/document.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +60 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -1
- package/dist/page.d.ts +22 -1
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +41 -0
- package/dist/page.js.map +1 -1
- package/dist/types.d.ts +271 -0
- package/dist/types.d.ts.map +1 -1
- package/lib/document.ts +70 -1
- package/lib/errors.ts +10 -0
- package/lib/index.ts +162 -0
- package/lib/page.ts +52 -0
- package/lib/types.ts +296 -0
- package/package.json +1 -1
- package/scripts/generate-fixtures.mjs +353 -0
- package/scripts/prebuilds.json +10 -10
- package/src/annotations_worker.h +1 -1
- package/src/assemble_worker.h +235 -0
- package/src/attachments_worker.h +1 -39
- package/src/attachments_write_worker.h +168 -0
- package/src/characters_worker.h +240 -0
- package/src/destinations_worker.h +160 -0
- package/src/document.h +86 -0
- package/src/document_io.h +78 -0
- package/src/flatten_worker.h +138 -0
- package/src/javascript_worker.h +105 -0
- package/src/napi_helpers.h +55 -0
- package/src/page.h +50 -0
- package/src/pdfium_addon.cc +314 -0
- package/src/signatures_worker.h +248 -0
- package/src/split_merge_worker.h +2 -93
- package/src/structtree_worker.h +189 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PDFiumDocument } from './document.js';
|
|
2
|
-
import type { MergeDocumentInput, MergeDocumentsOptions, SplitDocumentOptions } from './types.js';
|
|
2
|
+
import type { AddAttachmentsOptions, AssemblePagesOptions, AttachmentInput, FlattenDocumentOptions, MergeDocumentInput, MergeDocumentsOptions, NUpPagesOptions, SplitDocumentOptions } from './types.js';
|
|
3
3
|
type PdfInput = Buffer | string;
|
|
4
4
|
/**
|
|
5
5
|
* Opens a PDF document from a Buffer or file path.
|
|
@@ -20,9 +20,67 @@ export declare function mergeDocuments(inputs: Array<PdfInput | MergeDocumentInp
|
|
|
20
20
|
output: string;
|
|
21
21
|
}): Promise<void>;
|
|
22
22
|
export declare function mergeDocuments(inputs: Array<PdfInput | MergeDocumentInput>, options?: MergeDocumentsOptions): Promise<Buffer>;
|
|
23
|
+
/**
|
|
24
|
+
* Builds a new PDF from selected pages of `input`, in the order given.
|
|
25
|
+
*
|
|
26
|
+
* Unlike {@link splitDocument}, which only cuts a document into consecutive
|
|
27
|
+
* runs, the index list here is taken literally: pages may be reordered, left
|
|
28
|
+
* out, or repeated. `assemblePages(pdf, [3, 0, 0])` yields a three-page
|
|
29
|
+
* document whose first page is the original page 3 and whose next two are both
|
|
30
|
+
* the original page 0.
|
|
31
|
+
*/
|
|
32
|
+
export declare function assemblePages(input: PdfInput, pages: number[], options: AssemblePagesOptions & {
|
|
33
|
+
output: string;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
export declare function assemblePages(input: PdfInput, pages: number[], options?: AssemblePagesOptions): Promise<Buffer>;
|
|
36
|
+
/**
|
|
37
|
+
* Imposes `columns × rows` source pages onto each page of a new document —
|
|
38
|
+
* the classic "n-up" layout for handouts and proof sheets.
|
|
39
|
+
*
|
|
40
|
+
* The output sheet defaults to the size of the first source page, so a 2×2
|
|
41
|
+
* n-up of A4 pages lands on A4 with each source page scaled to a quarter.
|
|
42
|
+
*/
|
|
43
|
+
export declare function nUpPages(input: PdfInput, options: NUpPagesOptions & {
|
|
44
|
+
output: string;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
export declare function nUpPages(input: PdfInput, options: NUpPagesOptions): Promise<Buffer>;
|
|
47
|
+
/**
|
|
48
|
+
* Embeds files into a copy of `input`, returning the new PDF.
|
|
49
|
+
*
|
|
50
|
+
* **This does not produce a conformant PDF/A-3 e-invoice.** PDFium's write API
|
|
51
|
+
* reaches only the file name, the bytes and the `/Params` dates. It cannot set
|
|
52
|
+
* the MIME type (`/Subtype`), the description (`/Desc`), the
|
|
53
|
+
* `/AFRelationship` that marks an attachment as the invoice source, the catalog
|
|
54
|
+
* `/AF` array, an OutputIntent, or the XMP metadata — all of which ZUGFeRD,
|
|
55
|
+
* Factur-X and XRechnung require. Use this for ordinary attachments; reach for
|
|
56
|
+
* a PDF/A toolchain to *produce* e-invoices. Reading them back is fully
|
|
57
|
+
* supported via {@link PDFiumDocument.getAttachments}.
|
|
58
|
+
*/
|
|
59
|
+
export declare function addAttachments(input: PdfInput, attachments: AttachmentInput[], options: AddAttachmentsOptions & {
|
|
60
|
+
output: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
export declare function addAttachments(input: PdfInput, attachments: AttachmentInput[], options?: AddAttachmentsOptions): Promise<Buffer>;
|
|
63
|
+
/**
|
|
64
|
+
* Flattens annotations and form widgets into the page content of a copy of
|
|
65
|
+
* `input`, returning the new PDF.
|
|
66
|
+
*
|
|
67
|
+
* The result renders identically in every viewer but is no longer interactive,
|
|
68
|
+
* which is the point when archiving or handing a filled form to a system that
|
|
69
|
+
* ignores annotations.
|
|
70
|
+
*
|
|
71
|
+
* This bakes in the appearance streams the document already carries rather than
|
|
72
|
+
* regenerating them, since no form-fill environment is initialised. That is
|
|
73
|
+
* correct for any PDF whose widgets have valid `/AP` entries — what every
|
|
74
|
+
* mainstream producer writes. A form flagged `/NeedAppearances`, which asks the
|
|
75
|
+
* viewer to regenerate appearances itself, is the case this cannot help with.
|
|
76
|
+
*/
|
|
77
|
+
export declare function flattenDocument(input: PdfInput, options: FlattenDocumentOptions & {
|
|
78
|
+
output: string;
|
|
79
|
+
}): Promise<void>;
|
|
80
|
+
export declare function flattenDocument(input: PdfInput, options?: FlattenDocumentOptions): Promise<Buffer>;
|
|
23
81
|
export { concurrency } from './concurrency.js';
|
|
24
82
|
export { PDFiumDocument } from './document.js';
|
|
25
83
|
export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
|
|
26
84
|
export { PDFiumPage } from './page.js';
|
|
27
|
-
export type { Annotation, AnnotationBorder, AnnotationType, Attachment, Bookmark, DocumentMetadata, DocumentPermissions, FormField, FormFieldOption, FormFieldType, GetAttachmentOptions, ImageColorspace, ImagePageObject, ImageRenderOptions, Link, LinkActionType, MergeDocumentInput, MergeDocumentsOptions, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, SplitDocumentOptions, TextPageObject, TextRenderMode, } from './types.js';
|
|
85
|
+
export type { AddAttachmentsOptions, Annotation, AnnotationBorder, AnnotationType, AssemblePagesOptions, Attachment, AttachmentInput, Bookmark, DocumentMetadata, DestinationView, DocumentPermissions, FormField, FormFieldOption, FlattenDocumentOptions, FormFieldType, GetAttachmentOptions, GetCharactersOptions, GetSignatureContentsOptions, ImageColorspace, ImagePageObject, ImageRenderOptions, JavaScriptAction, Link, LinkActionType, MergeDocumentInput, MergeDocumentsOptions, NUpPagesOptions, NamedDestination, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, Signature, StructElement, SplitDocumentOptions, TextCharacter, TextPageObject, TextRenderMode, } from './types.js';
|
|
28
86
|
//# 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,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C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AM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EACV,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,2BAA2B,EAC3B,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,IAAI,EACJ,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ 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 { isNativeIndex } from './validate.js';
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
10
|
// ensure the dynamic linker can find libpdfium next to pdfium.node.
|
|
@@ -46,6 +47,63 @@ export async function mergeDocuments(inputs, options) {
|
|
|
46
47
|
throw parseNativeError(err);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
export async function assemblePages(input, pages, options) {
|
|
51
|
+
// ToInt32 in the native layer would wrap a fractional or oversized index onto
|
|
52
|
+
// a different, valid page and silently assemble the wrong document.
|
|
53
|
+
for (const page of pages) {
|
|
54
|
+
if (!isNativeIndex(page)) {
|
|
55
|
+
throw new RangeError(`Page index must be a 32-bit integer, got ${page}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return await withConcurrency(() => addon.assemblePages(input, pages, options));
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
throw parseNativeError(err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function nUpPages(input, options) {
|
|
66
|
+
// Validate here rather than natively so callers get a plain RangeError
|
|
67
|
+
// instead of a PDFiumError wrapping one.
|
|
68
|
+
for (const [name, value] of [
|
|
69
|
+
['columns', options.columns],
|
|
70
|
+
['rows', options.rows],
|
|
71
|
+
]) {
|
|
72
|
+
// isNativeIndex, not just Number.isInteger: the native layer coerces with
|
|
73
|
+
// ToInt32, so 2**32 + 2 would wrap to 2 and silently produce a different,
|
|
74
|
+
// perfectly valid layout instead of an error.
|
|
75
|
+
if (!isNativeIndex(value) || value < 1) {
|
|
76
|
+
throw new RangeError(`${name} must be a positive 32-bit integer, got ${value}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return await withConcurrency(() => addon.nUpPages(input, options));
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
throw parseNativeError(err);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export async function addAttachments(input, attachments, options) {
|
|
87
|
+
try {
|
|
88
|
+
return await withConcurrency(() => addon.addAttachments(input, attachments, options));
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
throw parseNativeError(err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export async function flattenDocument(input, options) {
|
|
95
|
+
for (const page of options?.pages ?? []) {
|
|
96
|
+
if (!isNativeIndex(page)) {
|
|
97
|
+
throw new RangeError(`Page index must be a 32-bit integer, got ${page}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return await withConcurrency(() => addon.flattenDocument(input, options));
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
throw parseNativeError(err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
49
107
|
export { concurrency } from './concurrency.js';
|
|
50
108
|
export { PDFiumDocument } from './document.js';
|
|
51
109
|
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/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
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/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAa9C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAA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AE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/page.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Annotation, FormField, GetAttachmentOptions, Link, NativePage, PageObject, PageObjectBounds, PageRenderOptions, SearchMatch, SearchOptions } from './types.js';
|
|
1
|
+
import type { Annotation, FormField, GetAttachmentOptions, GetCharactersOptions, Link, NativePage, PageObject, PageObjectBounds, PageRenderOptions, SearchMatch, SearchOptions, StructElement, TextCharacter } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* A page in a PDF document.
|
|
4
4
|
*/
|
|
@@ -26,6 +26,27 @@ export declare class PDFiumPage {
|
|
|
26
26
|
constructor(native: NativePage);
|
|
27
27
|
/** Extracts all text from the page. */
|
|
28
28
|
getText(): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Extracts every character with its bounding box, baseline origin, font and
|
|
31
|
+
* rotation — the geometry {@link getText} throws away.
|
|
32
|
+
*
|
|
33
|
+
* Character indices line up with {@link search} results and with the string
|
|
34
|
+
* returned by `getText()`, so a match can be mapped straight back to page
|
|
35
|
+
* coordinates. Dense pages can hold tens of thousands of characters; use
|
|
36
|
+
* `start` and `count` to page through instead of materialising all of them.
|
|
37
|
+
*/
|
|
38
|
+
getCharacters(options?: GetCharactersOptions): Promise<TextCharacter[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the tagged-PDF structure tree for this page — the logical outline
|
|
41
|
+
* (headings, paragraphs, tables, figures) that screen readers follow, and
|
|
42
|
+
* where alternate text lives.
|
|
43
|
+
*
|
|
44
|
+
* The tree is per-page: these are the elements whose content is on this page,
|
|
45
|
+
* not the whole document's tree. Returns an empty array for an untagged page;
|
|
46
|
+
* `document.metadata.isTagged` says up front whether there is anything to
|
|
47
|
+
* find.
|
|
48
|
+
*/
|
|
49
|
+
getStructTree(): Promise<StructElement[]>;
|
|
29
50
|
/** Renders the page to a file. */
|
|
30
51
|
render(options: PageRenderOptions & {
|
|
31
52
|
output: string;
|
package/dist/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,oBAAoB,EAGpB,IAAI,EACJ,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,UAAU;IAqBT,OAAO,CAAC,MAAM;IApB1B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,2FAA2F;IAC3F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,UAAU;IAYtC,uCAAuC;IACvC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,kCAAkC;IAClC,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;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AO,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;IAIvC;;;;;;;;OAQG;IACH,uBAAuB,CACrB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,oBAAoB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GACjD,OAAO,CAAC,IAAI,CAAC;IAChB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;IAavF,2CAA2C;IAC3C,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAGtC"}
|
package/dist/page.js
CHANGED
|
@@ -43,6 +43,47 @@ export class PDFiumPage {
|
|
|
43
43
|
getText() {
|
|
44
44
|
return withConcurrency(() => this.native.getText());
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Extracts every character with its bounding box, baseline origin, font and
|
|
48
|
+
* rotation — the geometry {@link getText} throws away.
|
|
49
|
+
*
|
|
50
|
+
* Character indices line up with {@link search} results and with the string
|
|
51
|
+
* returned by `getText()`, so a match can be mapped straight back to page
|
|
52
|
+
* coordinates. Dense pages can hold tens of thousands of characters; use
|
|
53
|
+
* `start` and `count` to page through instead of materialising all of them.
|
|
54
|
+
*/
|
|
55
|
+
getCharacters(options) {
|
|
56
|
+
const start = options?.start ?? 0;
|
|
57
|
+
const count = options?.count;
|
|
58
|
+
// Same 32-bit guard as elsewhere: a fractional or oversized value must not
|
|
59
|
+
// ToInt32-wrap into a different, silently valid range.
|
|
60
|
+
if (!isNativeIndex(start)) {
|
|
61
|
+
return Promise.reject(new RangeError(`Character start must be a 32-bit integer, got ${start}`));
|
|
62
|
+
}
|
|
63
|
+
if (count !== undefined && !isNativeIndex(count)) {
|
|
64
|
+
return Promise.reject(new RangeError(`Character count must be a 32-bit integer, got ${count}`));
|
|
65
|
+
}
|
|
66
|
+
if (start < 0) {
|
|
67
|
+
return Promise.reject(new RangeError(`Character start must not be negative, got ${start}`));
|
|
68
|
+
}
|
|
69
|
+
if (count !== undefined && count < 0) {
|
|
70
|
+
return Promise.reject(new RangeError(`Character count must not be negative, got ${count}`));
|
|
71
|
+
}
|
|
72
|
+
return withConcurrency(() => this.native.getCharacters(start, count ?? -1));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns the tagged-PDF structure tree for this page — the logical outline
|
|
76
|
+
* (headings, paragraphs, tables, figures) that screen readers follow, and
|
|
77
|
+
* where alternate text lives.
|
|
78
|
+
*
|
|
79
|
+
* The tree is per-page: these are the elements whose content is on this page,
|
|
80
|
+
* not the whole document's tree. Returns an empty array for an untagged page;
|
|
81
|
+
* `document.metadata.isTagged` says up front whether there is anything to
|
|
82
|
+
* find.
|
|
83
|
+
*/
|
|
84
|
+
getStructTree() {
|
|
85
|
+
return withConcurrency(() => this.native.getStructTree());
|
|
86
|
+
}
|
|
46
87
|
render(options) {
|
|
47
88
|
return withConcurrency(() => this.native.render(options));
|
|
48
89
|
}
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAmB9C;;GAEG;AACH,MAAM,OAAO,UAAU;IAqBD;IApBpB,+CAA+C;IACtC,KAAK,CAAS;I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E,gEAAgE;QAChE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,UAAU,CAAC,kDAAkD,KAAK,EAAE,CAAC,CAC1E,CAAC;QACJ,CAAC;QACD,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5F,CAAC;IAED,2CAA2C;IAC3C,aAAa;QACX,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -110,6 +110,111 @@ export interface OtherPageObject extends BasePageObject {
|
|
|
110
110
|
type: 'path' | 'shading' | 'form' | 'unknown';
|
|
111
111
|
}
|
|
112
112
|
export type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
|
|
113
|
+
/**
|
|
114
|
+
* A single character on a page, with the geometry `getText()` discards.
|
|
115
|
+
*/
|
|
116
|
+
export interface TextCharacter {
|
|
117
|
+
/** 0-based index of this character in the page's text. */
|
|
118
|
+
index: number;
|
|
119
|
+
/**
|
|
120
|
+
* The character itself.
|
|
121
|
+
*
|
|
122
|
+
* Empty string when the glyph has no Unicode mapping — check
|
|
123
|
+
* `hasUnicodeMapError` before trusting it — and also on the *second* entry of
|
|
124
|
+
* a non-BMP character. PDFium reports one UTF-16 code unit per index, so an
|
|
125
|
+
* emoji occupies two entries; the whole character is emitted on the first and
|
|
126
|
+
* the second is an empty continuation. That keeps indices aligned with
|
|
127
|
+
* `getText()` while `chars.map((c) => c.char).join('')` still reproduces it
|
|
128
|
+
* exactly.
|
|
129
|
+
*/
|
|
130
|
+
char: string;
|
|
131
|
+
/**
|
|
132
|
+
* The raw UTF-16 code unit at this index, or 0 if the glyph has no mapping.
|
|
133
|
+
* For a non-BMP character this is the high surrogate on the first entry and
|
|
134
|
+
* the low surrogate on the second, not the combined code point.
|
|
135
|
+
*/
|
|
136
|
+
unicode: number;
|
|
137
|
+
/**
|
|
138
|
+
* Tight bounding box in page points, hugging the glyph's ink. Absent if
|
|
139
|
+
* PDFium cannot determine it.
|
|
140
|
+
*/
|
|
141
|
+
bounds?: PageObjectBounds;
|
|
142
|
+
/** X coordinate of the baseline origin in page points. Absent if unavailable. */
|
|
143
|
+
x?: number;
|
|
144
|
+
/** Y coordinate of the baseline origin in page points. Absent if unavailable. */
|
|
145
|
+
y?: number;
|
|
146
|
+
/** Font size in points (the typographic "em" size). */
|
|
147
|
+
fontSize: number;
|
|
148
|
+
/** PostScript name of the font (e.g. 'Helvetica-Bold'). Empty string if unavailable. */
|
|
149
|
+
fontName: string;
|
|
150
|
+
/** Raw PDF font descriptor flags bitmask (see PDF spec Table 123). */
|
|
151
|
+
fontFlags: number;
|
|
152
|
+
/**
|
|
153
|
+
* Font weight (e.g. 400 = normal, 700 = bold). Absent when the font declares
|
|
154
|
+
* none — which is the case for the non-embedded standard fonts, so do not
|
|
155
|
+
* treat its absence as an error.
|
|
156
|
+
*/
|
|
157
|
+
fontWeight?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Rotation of the character in radians, normalized to `[0, 2π)`. 0 for
|
|
160
|
+
* upright text.
|
|
161
|
+
*
|
|
162
|
+
* Note the direction: PDFium derives this as `atan2(c, a)` from the text
|
|
163
|
+
* matrix, so it runs *clockwise*. Text rotated 45° counterclockwise on the
|
|
164
|
+
* page reports ≈ 5.4978 (2π − π/4), not ≈ 0.7854.
|
|
165
|
+
*/
|
|
166
|
+
angle: number;
|
|
167
|
+
/**
|
|
168
|
+
* Whether PDFium synthesized this character rather than reading it from the
|
|
169
|
+
* content stream — line breaks between text runs, and spaces inferred from
|
|
170
|
+
* glyph spacing. Synthesized characters carry no real font, so `fontName` is
|
|
171
|
+
* empty, `fontSize` is 1 and `fontWeight` is absent. Useful when mapping text
|
|
172
|
+
* offsets back to the original PDF.
|
|
173
|
+
*/
|
|
174
|
+
isGenerated: boolean;
|
|
175
|
+
/** Whether this character is a hyphen (relevant when de-hyphenating lines). */
|
|
176
|
+
isHyphen: boolean;
|
|
177
|
+
/** Whether the glyph has no reliable Unicode mapping, making `char` unreliable. */
|
|
178
|
+
hasUnicodeMapError: boolean;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* A node in a tagged PDF's structure tree — the logical document outline
|
|
182
|
+
* (headings, paragraphs, tables, figures) behind the visual layout, which is
|
|
183
|
+
* what screen readers follow.
|
|
184
|
+
*/
|
|
185
|
+
export interface StructElement {
|
|
186
|
+
/** Structure type (/S), e.g. 'H1', 'P', 'Table', 'Figure'. */
|
|
187
|
+
type: string;
|
|
188
|
+
/** Object type (/Type), normally 'StructElem'. Absent if not set. */
|
|
189
|
+
objType?: string;
|
|
190
|
+
/** Human-readable title (/T). Absent if not set. */
|
|
191
|
+
title?: string;
|
|
192
|
+
/** Alternate text (/Alt) — the accessibility description. Absent if not set. */
|
|
193
|
+
altText?: string;
|
|
194
|
+
/** Replacement text (/ActualText) for content whose glyphs differ from its meaning. */
|
|
195
|
+
actualText?: string;
|
|
196
|
+
/** Element identifier (/ID). Absent if not set. */
|
|
197
|
+
id?: string;
|
|
198
|
+
/** Language override (/Lang) for this subtree, e.g. 'de-DE'. Absent if not set. */
|
|
199
|
+
lang?: string;
|
|
200
|
+
/** Marked-content ID tying this element to page content. Absent if the element has none. */
|
|
201
|
+
markedContentId?: number;
|
|
202
|
+
/**
|
|
203
|
+
* Child elements. Absent when the element has no element children.
|
|
204
|
+
*
|
|
205
|
+
* The walk is capped at 100,000 elements per page. PDFium's structure tree is
|
|
206
|
+
* a DAG, so a document whose `/K` arrays repeat the same child expands
|
|
207
|
+
* exponentially when flattened into a tree; the cap bounds that. Real
|
|
208
|
+
* documents do not come close to it.
|
|
209
|
+
*/
|
|
210
|
+
children?: StructElement[];
|
|
211
|
+
}
|
|
212
|
+
export interface GetCharactersOptions {
|
|
213
|
+
/** First character index to return (default: 0). */
|
|
214
|
+
start?: number;
|
|
215
|
+
/** How many characters to return (default: all remaining). */
|
|
216
|
+
count?: number;
|
|
217
|
+
}
|
|
113
218
|
export interface SearchOptions {
|
|
114
219
|
/** Match case when searching (default: false). */
|
|
115
220
|
caseSensitive?: boolean;
|
|
@@ -336,6 +441,90 @@ export interface GetAttachmentOptions {
|
|
|
336
441
|
/** Write the attachment bytes to this file path instead of returning a Buffer. */
|
|
337
442
|
output?: string;
|
|
338
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* A digital signature as declared by the PDF.
|
|
446
|
+
*
|
|
447
|
+
* These values come straight from the signature dictionary — nothing here is
|
|
448
|
+
* cryptographically verified. A present, well-formed signature says only that
|
|
449
|
+
* the document *claims* to be signed.
|
|
450
|
+
*/
|
|
451
|
+
export interface Signature {
|
|
452
|
+
/** 0-based index of the signature in the document's AcroForm field list. */
|
|
453
|
+
index: number;
|
|
454
|
+
/**
|
|
455
|
+
* Encoding of the signature value (/SubFilter), e.g. 'adbe.pkcs7.detached'
|
|
456
|
+
* or 'ETSI.CAdES.detached'. Empty string if the PDF omits it.
|
|
457
|
+
*/
|
|
458
|
+
subFilter: string;
|
|
459
|
+
/** Reason given for signing (/Reason). Absent if not set. */
|
|
460
|
+
reason?: string;
|
|
461
|
+
/**
|
|
462
|
+
* Time of signing (/M) as a PDF date string (e.g. "D:20250101120000+01'00'").
|
|
463
|
+
* Absent if not set. For PKCS#7 signatures the authoritative time is usually
|
|
464
|
+
* inside the signature blob instead; use this only as a fallback.
|
|
465
|
+
*/
|
|
466
|
+
time?: string;
|
|
467
|
+
/**
|
|
468
|
+
* Certification level for a DocMDP signature: 1 = no changes allowed,
|
|
469
|
+
* 2 = form fill-in and signing allowed, 3 = additionally annotations allowed.
|
|
470
|
+
* Absent for an ordinary (non-certifying) signature.
|
|
471
|
+
*/
|
|
472
|
+
docMdpPermission?: 1 | 2 | 3;
|
|
473
|
+
/**
|
|
474
|
+
* The /ByteRange array covered by the signature digest: a flat list of
|
|
475
|
+
* (offset, length) pairs, exactly as stored in the PDF. A signature covers
|
|
476
|
+
* the whole file when the last pair ends at the file size — anything less
|
|
477
|
+
* means content was appended after signing.
|
|
478
|
+
*/
|
|
479
|
+
byteRange: number[];
|
|
480
|
+
/**
|
|
481
|
+
* Size in bytes of the signature value (/Contents). Read the bytes
|
|
482
|
+
* themselves with {@link PDFiumDocument.getSignatureContents}.
|
|
483
|
+
*/
|
|
484
|
+
contentsLength: number;
|
|
485
|
+
}
|
|
486
|
+
export interface GetSignatureContentsOptions {
|
|
487
|
+
/** Write the signature bytes to this file path instead of returning a Buffer. */
|
|
488
|
+
output?: string;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* A document-level JavaScript action — a script a viewer runs when the
|
|
492
|
+
* document opens.
|
|
493
|
+
*/
|
|
494
|
+
export interface JavaScriptAction {
|
|
495
|
+
/** 0-based index in the document's /Names /JavaScript tree. */
|
|
496
|
+
index: number;
|
|
497
|
+
/** Entry name in the JavaScript name tree. Empty string if unnamed. */
|
|
498
|
+
name: string;
|
|
499
|
+
/** The script source, returned as inert text. Empty string if unreadable. */
|
|
500
|
+
script: string;
|
|
501
|
+
}
|
|
502
|
+
/** How a viewer should frame the target page when following a destination. */
|
|
503
|
+
export type DestinationView = 'xyz' | 'fit' | 'fitH' | 'fitV' | 'fitR' | 'fitB' | 'fitBH' | 'fitBV' | 'unknown';
|
|
504
|
+
/**
|
|
505
|
+
* A named destination — an anchor that GoTo actions and external links target
|
|
506
|
+
* by name instead of by page number.
|
|
507
|
+
*/
|
|
508
|
+
export interface NamedDestination {
|
|
509
|
+
/** The destination's name, e.g. 'Chapter2'. */
|
|
510
|
+
name: string;
|
|
511
|
+
/** Target page index. Absent if the destination cannot be resolved to a page. */
|
|
512
|
+
pageIndex?: number;
|
|
513
|
+
/** Fit type declared by the destination. */
|
|
514
|
+
view: DestinationView;
|
|
515
|
+
/**
|
|
516
|
+
* Raw view parameters, up to four numbers whose meaning depends on `view` —
|
|
517
|
+
* for example `fitR` carries [left, bottom, right, top] and `fitH` a single
|
|
518
|
+
* top coordinate. Empty for `fit` and `fitB`, which take none.
|
|
519
|
+
*/
|
|
520
|
+
viewParams: number[];
|
|
521
|
+
/** Destination X coordinate. Only set for `xyz` destinations that specify one. */
|
|
522
|
+
destX?: number;
|
|
523
|
+
/** Destination Y coordinate. Only set for `xyz` destinations that specify one. */
|
|
524
|
+
destY?: number;
|
|
525
|
+
/** Destination zoom level. Only set for `xyz` destinations that specify one. */
|
|
526
|
+
destZoom?: number;
|
|
527
|
+
}
|
|
339
528
|
export interface NativePage {
|
|
340
529
|
readonly number: number;
|
|
341
530
|
readonly width: number;
|
|
@@ -347,6 +536,7 @@ export interface NativePage {
|
|
|
347
536
|
readonly cropBox?: PageObjectBounds;
|
|
348
537
|
readonly trimBox?: PageObjectBounds;
|
|
349
538
|
getText(): Promise<string>;
|
|
539
|
+
getCharacters(start?: number, count?: number): Promise<TextCharacter[]>;
|
|
350
540
|
render(options?: PageRenderOptions): Promise<Buffer | void>;
|
|
351
541
|
getObject(index: number): Promise<PageObject>;
|
|
352
542
|
renderImage(index: number, options?: ImageRenderOptions): Promise<Buffer | void>;
|
|
@@ -355,6 +545,7 @@ export interface NativePage {
|
|
|
355
545
|
getAnnotations(): Promise<Annotation[]>;
|
|
356
546
|
getAnnotationAttachment(index: number, outputPath?: string): Promise<Buffer | undefined>;
|
|
357
547
|
getFormFields(): Promise<FormField[]>;
|
|
548
|
+
getStructTree(): Promise<StructElement[]>;
|
|
358
549
|
close(): void;
|
|
359
550
|
}
|
|
360
551
|
export interface NativeDocument {
|
|
@@ -364,6 +555,10 @@ export interface NativeDocument {
|
|
|
364
555
|
getBookmarks(): Promise<Bookmark[]>;
|
|
365
556
|
getAttachments(): Promise<Attachment[]>;
|
|
366
557
|
getAttachment(index: number, outputPath?: string): Promise<Buffer | undefined>;
|
|
558
|
+
getSignatures(): Promise<Signature[]>;
|
|
559
|
+
getSignatureContents(index: number, outputPath?: string): Promise<Buffer | undefined>;
|
|
560
|
+
getJavaScriptActions(): Promise<JavaScriptAction[]>;
|
|
561
|
+
getNamedDestinations(): Promise<NamedDestination[]>;
|
|
367
562
|
destroy(): void;
|
|
368
563
|
}
|
|
369
564
|
export interface SplitDocumentOptions {
|
|
@@ -382,6 +577,78 @@ export interface MergeDocumentsOptions {
|
|
|
382
577
|
/** Write to this file path instead of returning a Buffer. */
|
|
383
578
|
output?: string;
|
|
384
579
|
}
|
|
580
|
+
export interface AssemblePagesOptions {
|
|
581
|
+
/** Write to this file path instead of returning a Buffer. */
|
|
582
|
+
output?: string;
|
|
583
|
+
/** Password for the source PDF (if encrypted). */
|
|
584
|
+
password?: string;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* A file to embed with {@link addAttachments}.
|
|
588
|
+
*
|
|
589
|
+
* There is deliberately no `mimeType` or `description` field. The MIME type is
|
|
590
|
+
* `/Subtype` on the embedded-file stream and the description is `/Desc` on the
|
|
591
|
+
* filespec dictionary; PDFium's write API reaches neither in the bundled build,
|
|
592
|
+
* and accepting those values only to drop them silently would be worse than not
|
|
593
|
+
* offering them. Note this is an asymmetry with reading: `Attachment.mimeType`
|
|
594
|
+
* is reported when a PDF already carries it.
|
|
595
|
+
*/
|
|
596
|
+
export interface AttachmentInput {
|
|
597
|
+
/**
|
|
598
|
+
* File name to store in the /EmbeddedFiles name tree, e.g. 'report.xml'.
|
|
599
|
+
* Must be non-empty and not already present in the document.
|
|
600
|
+
*/
|
|
601
|
+
name: string;
|
|
602
|
+
/** File contents. */
|
|
603
|
+
data: Buffer;
|
|
604
|
+
/**
|
|
605
|
+
* Creation date as a PDF date string, e.g. 'D:20250101120000Z'. Defaults to
|
|
606
|
+
* the current time, so set it explicitly for reproducible output.
|
|
607
|
+
*/
|
|
608
|
+
creationDate?: string;
|
|
609
|
+
/** Modification date as a PDF date string. */
|
|
610
|
+
modDate?: string;
|
|
611
|
+
}
|
|
612
|
+
export interface AddAttachmentsOptions {
|
|
613
|
+
/** Write to this file path instead of returning a Buffer. */
|
|
614
|
+
output?: string;
|
|
615
|
+
/** Password for the source PDF (if encrypted). */
|
|
616
|
+
password?: string;
|
|
617
|
+
}
|
|
618
|
+
export interface FlattenDocumentOptions {
|
|
619
|
+
/**
|
|
620
|
+
* Which appearance to bake in: `'display'` (default) or `'print'`. They
|
|
621
|
+
* differ for annotations whose appearance dictionary distinguishes the two —
|
|
622
|
+
* a watermark marked print-only, for instance.
|
|
623
|
+
*/
|
|
624
|
+
usage?: 'display' | 'print';
|
|
625
|
+
/**
|
|
626
|
+
* Only flatten these page indices. Defaults to every page when omitted.
|
|
627
|
+
*
|
|
628
|
+
* An explicitly empty array flattens *nothing* and returns an unchanged copy —
|
|
629
|
+
* so a selection computed by a filter that happens to match no pages is a
|
|
630
|
+
* no-op rather than a document stripped of every annotation.
|
|
631
|
+
*/
|
|
632
|
+
pages?: number[];
|
|
633
|
+
/** Write to this file path instead of returning a Buffer. */
|
|
634
|
+
output?: string;
|
|
635
|
+
/** Password for the source PDF (if encrypted). */
|
|
636
|
+
password?: string;
|
|
637
|
+
}
|
|
638
|
+
export interface NUpPagesOptions {
|
|
639
|
+
/** Number of source pages placed side by side across each output page. */
|
|
640
|
+
columns: number;
|
|
641
|
+
/** Number of source pages stacked down each output page. */
|
|
642
|
+
rows: number;
|
|
643
|
+
/** Output page width in points. Defaults to the width of the first source page. */
|
|
644
|
+
width?: number;
|
|
645
|
+
/** Output page height in points. Defaults to the height of the first source page. */
|
|
646
|
+
height?: number;
|
|
647
|
+
/** Write to this file path instead of returning a Buffer. */
|
|
648
|
+
output?: string;
|
|
649
|
+
/** Password for the source PDF (if encrypted). */
|
|
650
|
+
password?: string;
|
|
651
|
+
}
|
|
385
652
|
export interface NativeAddon {
|
|
386
653
|
loadDocument(input: Buffer | string, password?: string): Promise<NativeDocument>;
|
|
387
654
|
splitDocument(input: Buffer | string, splitAt: number[], options?: {
|
|
@@ -394,6 +661,10 @@ export interface NativeAddon {
|
|
|
394
661
|
}>, options?: {
|
|
395
662
|
output?: string;
|
|
396
663
|
}): Promise<Buffer | undefined>;
|
|
664
|
+
assemblePages(input: Buffer | string, pages: number[], options?: AssemblePagesOptions): Promise<Buffer | undefined>;
|
|
665
|
+
nUpPages(input: Buffer | string, options: NUpPagesOptions): Promise<Buffer | undefined>;
|
|
666
|
+
addAttachments(input: Buffer | string, attachments: AttachmentInput[], options?: AddAttachmentsOptions): Promise<Buffer | undefined>;
|
|
667
|
+
flattenDocument(input: Buffer | string, options?: FlattenDocumentOptions): Promise<Buffer | undefined>;
|
|
397
668
|
}
|
|
398
669
|
export {};
|
|
399
670
|
//# sourceMappingURL=types.d.ts.map
|