pdfium-native 0.7.0 → 0.9.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +324 -4
  3. package/dist/document.d.ts +43 -2
  4. package/dist/document.d.ts.map +1 -1
  5. package/dist/document.js +49 -6
  6. package/dist/document.js.map +1 -1
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +9 -0
  9. package/dist/errors.js.map +1 -1
  10. package/dist/index.d.ts +60 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +55 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/page.d.ts +35 -1
  15. package/dist/page.d.ts.map +1 -1
  16. package/dist/page.js +51 -0
  17. package/dist/page.js.map +1 -1
  18. package/dist/types.d.ts +255 -0
  19. package/dist/types.d.ts.map +1 -1
  20. package/dist/validate.d.ts +14 -0
  21. package/dist/validate.d.ts.map +1 -0
  22. package/dist/validate.js +16 -0
  23. package/dist/validate.js.map +1 -0
  24. package/lib/document.ts +80 -7
  25. package/lib/errors.ts +10 -0
  26. package/lib/index.ts +159 -0
  27. package/lib/page.ts +80 -0
  28. package/lib/types.ts +280 -0
  29. package/lib/validate.ts +15 -0
  30. package/package.json +1 -1
  31. package/scripts/generate-fixtures.mjs +310 -0
  32. package/scripts/prebuilds.json +10 -10
  33. package/src/annotations_worker.h +111 -0
  34. package/src/assemble_worker.h +235 -0
  35. package/src/attachments_worker.h +44 -45
  36. package/src/attachments_write_worker.h +158 -0
  37. package/src/characters_worker.h +197 -0
  38. package/src/destinations_worker.h +160 -0
  39. package/src/document.h +86 -0
  40. package/src/document_io.h +78 -0
  41. package/src/flatten_worker.h +133 -0
  42. package/src/javascript_worker.h +105 -0
  43. package/src/napi_helpers.h +55 -0
  44. package/src/page.h +82 -0
  45. package/src/pdfium_addon.cc +310 -0
  46. package/src/signatures_worker.h +248 -0
  47. package/src/split_merge_worker.h +2 -93
  48. package/src/structtree_worker.h +164 -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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EAErB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAKpB,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAgBhC;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAM9F;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,oBAAoB,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GACpD,OAAO,CAAC,IAAI,CAAC,CAAC;AACjB,wB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AmB,EACnB,mBAAmB,GACpB,MAAM,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,60 @@ 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
+ if (!Number.isInteger(value) || value < 1) {
73
+ throw new RangeError(`${name} must be a positive integer, got ${value}`);
74
+ }
75
+ }
76
+ try {
77
+ return await withConcurrency(() => addon.nUpPages(input, options));
78
+ }
79
+ catch (err) {
80
+ throw parseNativeError(err);
81
+ }
82
+ }
83
+ export async function addAttachments(input, attachments, options) {
84
+ try {
85
+ return await withConcurrency(() => addon.addAttachments(input, attachments, options));
86
+ }
87
+ catch (err) {
88
+ throw parseNativeError(err);
89
+ }
90
+ }
91
+ export async function flattenDocument(input, options) {
92
+ for (const page of options?.pages ?? []) {
93
+ if (!isNativeIndex(page)) {
94
+ throw new RangeError(`Page index must be a 32-bit integer, got ${page}`);
95
+ }
96
+ }
97
+ try {
98
+ return await withConcurrency(() => addon.flattenDocument(input, options));
99
+ }
100
+ catch (err) {
101
+ throw parseNativeError(err);
102
+ }
103
+ }
49
104
  export { concurrency } from './concurrency.js';
50
105
  export { PDFiumDocument } from './document.js';
51
106
  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,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AAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,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, 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;
@@ -44,6 +65,19 @@ export declare class PDFiumPage {
44
65
  search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
45
66
  /** Returns all annotations on the page. */
46
67
  getAnnotations(): Promise<Annotation[]>;
68
+ /**
69
+ * Reads the embedded file of the file-attachment annotation at `index`
70
+ * (the annotation's {@link Annotation.index}). Use this for page-level
71
+ * `'fileattachment'` (paperclip) annotations; for document-level embedded
72
+ * files (e.g. ZUGFeRD `factur-x.xml`) use `document.getAttachment` instead.
73
+ *
74
+ * Rejects if the annotation at `index` is not a file attachment or has no
75
+ * embedded file.
76
+ */
77
+ getAnnotationAttachment(index: number, options: GetAttachmentOptions & {
78
+ output: string;
79
+ }): Promise<void>;
80
+ getAnnotationAttachment(index: number, options?: GetAttachmentOptions): Promise<Buffer>;
47
81
  /** Returns all form fields on the page. */
48
82
  getFormFields(): Promise<FormField[]>;
49
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EAGT,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,C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AAqC;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;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
@@ -1,4 +1,5 @@
1
1
  import { withConcurrency } from './concurrency.js';
2
+ import { isNativeIndex } from './validate.js';
2
3
  /**
3
4
  * A page in a PDF document.
4
5
  */
@@ -42,6 +43,47 @@ export class PDFiumPage {
42
43
  getText() {
43
44
  return withConcurrency(() => this.native.getText());
44
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
+ }
45
87
  render(options) {
46
88
  return withConcurrency(() => this.native.render(options));
47
89
  }
@@ -78,6 +120,15 @@ export class PDFiumPage {
78
120
  getAnnotations() {
79
121
  return withConcurrency(() => this.native.getAnnotations());
80
122
  }
123
+ getAnnotationAttachment(index, options) {
124
+ // Reject indices the native ToInt32 coercion would silently alter (see
125
+ // isNativeIndex): a NaN/fractional or out-of-32-bit index must not wrap
126
+ // onto a valid, different annotation and return the wrong file.
127
+ if (!isNativeIndex(index)) {
128
+ return Promise.reject(new RangeError(`Annotation index must be a 32-bit integer, got ${index}`));
129
+ }
130
+ return withConcurrency(() => this.native.getAnnotationAttachment(index, options?.output));
131
+ }
81
132
  /** Returns all form fields on the page. */
82
133
  getFormFields() {
83
134
  return withConcurrency(() => this.native.getFormFields());
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;AAenD;;GAEG;AACH,MAAM,OAAO,UAAU;IAqBD;IApBpB,+CAA+C;IACtC,KAAK,CAAS;IACvB,gDAAg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,CAAC,CAAC;IACvD,CAAC;IAED,wFAAwF;IACxF,MAAM,CAAC,IAAY,EAAE,OAAuB;QAC1C,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,2CAA2C;IAC3C,cAAc;QACZ,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7D,CAAC;IAgBD,uBAAuB,CAAC,KAAa,EAAE,OAA8B;QACnE,uEAAuE;QACvE,wEAAwE;QACxE,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,89 @@ 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. Empty string when the glyph has no Unicode mapping —
121
+ * check `hasUnicodeMapError` before trusting it.
122
+ */
123
+ char: string;
124
+ /** Unicode code point, or 0 if the glyph has no mapping. */
125
+ unicode: number;
126
+ /**
127
+ * Tight bounding box in page points, hugging the glyph's ink. Absent if
128
+ * PDFium cannot determine it.
129
+ */
130
+ bounds?: PageObjectBounds;
131
+ /** X coordinate of the baseline origin in page points. Absent if unavailable. */
132
+ x?: number;
133
+ /** Y coordinate of the baseline origin in page points. Absent if unavailable. */
134
+ y?: number;
135
+ /** Font size in points (the typographic "em" size). */
136
+ fontSize: number;
137
+ /** PostScript name of the font (e.g. 'Helvetica-Bold'). Empty string if unavailable. */
138
+ fontName: string;
139
+ /** Raw PDF font descriptor flags bitmask (see PDF spec Table 123). */
140
+ fontFlags: number;
141
+ /** Font weight (e.g. 400 = normal, 700 = bold). Absent if unavailable. */
142
+ fontWeight?: number;
143
+ /**
144
+ * Rotation of the character in radians, normalized to `[0, 2π)`. 0 for
145
+ * upright text.
146
+ *
147
+ * Note the direction: PDFium derives this as `atan2(c, a)` from the text
148
+ * matrix, so it runs *clockwise*. Text rotated 45° counterclockwise on the
149
+ * page reports ≈ 5.4978 (2π − π/4), not ≈ 0.7854.
150
+ */
151
+ angle: number;
152
+ /**
153
+ * Whether PDFium synthesized this character rather than reading it from the
154
+ * content stream — line breaks between text runs, and spaces inferred from
155
+ * glyph spacing. Synthesized characters carry no real font, so `fontName` is
156
+ * empty, `fontSize` is 1 and `fontWeight` is absent. Useful when mapping text
157
+ * offsets back to the original PDF.
158
+ */
159
+ isGenerated: boolean;
160
+ /** Whether this character is a hyphen (relevant when de-hyphenating lines). */
161
+ isHyphen: boolean;
162
+ /** Whether the glyph has no reliable Unicode mapping, making `char` unreliable. */
163
+ hasUnicodeMapError: boolean;
164
+ }
165
+ /**
166
+ * A node in a tagged PDF's structure tree — the logical document outline
167
+ * (headings, paragraphs, tables, figures) behind the visual layout, which is
168
+ * what screen readers follow.
169
+ */
170
+ export interface StructElement {
171
+ /** Structure type (/S), e.g. 'H1', 'P', 'Table', 'Figure'. */
172
+ type: string;
173
+ /** Object type (/Type), normally 'StructElem'. Absent if not set. */
174
+ objType?: string;
175
+ /** Human-readable title (/T). Absent if not set. */
176
+ title?: string;
177
+ /** Alternate text (/Alt) — the accessibility description. Absent if not set. */
178
+ altText?: string;
179
+ /** Replacement text (/ActualText) for content whose glyphs differ from its meaning. */
180
+ actualText?: string;
181
+ /** Element identifier (/ID). Absent if not set. */
182
+ id?: string;
183
+ /** Language override (/Lang) for this subtree, e.g. 'de-DE'. Absent if not set. */
184
+ lang?: string;
185
+ /** Marked-content ID tying this element to page content. Absent if the element has none. */
186
+ markedContentId?: number;
187
+ /** Child elements. Absent when the element has no element children. */
188
+ children?: StructElement[];
189
+ }
190
+ export interface GetCharactersOptions {
191
+ /** First character index to return (default: 0). */
192
+ start?: number;
193
+ /** How many characters to return (default: all remaining). */
194
+ count?: number;
195
+ }
113
196
  export interface SearchOptions {
114
197
  /** Match case when searching (default: false). */
115
198
  caseSensitive?: boolean;
@@ -166,8 +249,19 @@ export interface QuadPoints {
166
249
  y4: number;
167
250
  }
168
251
  export interface Annotation {
252
+ /**
253
+ * 0-based index of this annotation on the page. Pass it to
254
+ * {@link NativePage.getAnnotationAttachment} to read a file-attachment
255
+ * annotation's embedded bytes.
256
+ */
257
+ index: number;
169
258
  /** Annotation subtype (e.g. 'highlight', 'text', 'link'). */
170
259
  type: AnnotationType;
260
+ /**
261
+ * For `'fileattachment'` annotations: the embedded file's name
262
+ * (e.g. 'report.pdf'). Absent for other annotation types.
263
+ */
264
+ fileName?: string;
171
265
  /** Bounding box in page coordinates, if available. */
172
266
  bounds?: PageObjectBounds;
173
267
  /** Text contents of the annotation. */
@@ -325,6 +419,90 @@ export interface GetAttachmentOptions {
325
419
  /** Write the attachment bytes to this file path instead of returning a Buffer. */
326
420
  output?: string;
327
421
  }
422
+ /**
423
+ * A digital signature as declared by the PDF.
424
+ *
425
+ * These values come straight from the signature dictionary — nothing here is
426
+ * cryptographically verified. A present, well-formed signature says only that
427
+ * the document *claims* to be signed.
428
+ */
429
+ export interface Signature {
430
+ /** 0-based index of the signature in the document's AcroForm field list. */
431
+ index: number;
432
+ /**
433
+ * Encoding of the signature value (/SubFilter), e.g. 'adbe.pkcs7.detached'
434
+ * or 'ETSI.CAdES.detached'. Empty string if the PDF omits it.
435
+ */
436
+ subFilter: string;
437
+ /** Reason given for signing (/Reason). Absent if not set. */
438
+ reason?: string;
439
+ /**
440
+ * Time of signing (/M) as a PDF date string (e.g. "D:20250101120000+01'00'").
441
+ * Absent if not set. For PKCS#7 signatures the authoritative time is usually
442
+ * inside the signature blob instead; use this only as a fallback.
443
+ */
444
+ time?: string;
445
+ /**
446
+ * Certification level for a DocMDP signature: 1 = no changes allowed,
447
+ * 2 = form fill-in and signing allowed, 3 = additionally annotations allowed.
448
+ * Absent for an ordinary (non-certifying) signature.
449
+ */
450
+ docMdpPermission?: 1 | 2 | 3;
451
+ /**
452
+ * The /ByteRange array covered by the signature digest: a flat list of
453
+ * (offset, length) pairs, exactly as stored in the PDF. A signature covers
454
+ * the whole file when the last pair ends at the file size — anything less
455
+ * means content was appended after signing.
456
+ */
457
+ byteRange: number[];
458
+ /**
459
+ * Size in bytes of the signature value (/Contents). Read the bytes
460
+ * themselves with {@link PDFiumDocument.getSignatureContents}.
461
+ */
462
+ contentsLength: number;
463
+ }
464
+ export interface GetSignatureContentsOptions {
465
+ /** Write the signature bytes to this file path instead of returning a Buffer. */
466
+ output?: string;
467
+ }
468
+ /**
469
+ * A document-level JavaScript action — a script a viewer runs when the
470
+ * document opens.
471
+ */
472
+ export interface JavaScriptAction {
473
+ /** 0-based index in the document's /Names /JavaScript tree. */
474
+ index: number;
475
+ /** Entry name in the JavaScript name tree. Empty string if unnamed. */
476
+ name: string;
477
+ /** The script source, returned as inert text. Empty string if unreadable. */
478
+ script: string;
479
+ }
480
+ /** How a viewer should frame the target page when following a destination. */
481
+ export type DestinationView = 'xyz' | 'fit' | 'fitH' | 'fitV' | 'fitR' | 'fitB' | 'fitBH' | 'fitBV' | 'unknown';
482
+ /**
483
+ * A named destination — an anchor that GoTo actions and external links target
484
+ * by name instead of by page number.
485
+ */
486
+ export interface NamedDestination {
487
+ /** The destination's name, e.g. 'Chapter2'. */
488
+ name: string;
489
+ /** Target page index. Absent if the destination cannot be resolved to a page. */
490
+ pageIndex?: number;
491
+ /** Fit type declared by the destination. */
492
+ view: DestinationView;
493
+ /**
494
+ * Raw view parameters, up to four numbers whose meaning depends on `view` —
495
+ * for example `fitR` carries [left, bottom, right, top] and `fitH` a single
496
+ * top coordinate. Empty for `fit` and `fitB`, which take none.
497
+ */
498
+ viewParams: number[];
499
+ /** Destination X coordinate. Only set for `xyz` destinations that specify one. */
500
+ destX?: number;
501
+ /** Destination Y coordinate. Only set for `xyz` destinations that specify one. */
502
+ destY?: number;
503
+ /** Destination zoom level. Only set for `xyz` destinations that specify one. */
504
+ destZoom?: number;
505
+ }
328
506
  export interface NativePage {
329
507
  readonly number: number;
330
508
  readonly width: number;
@@ -336,13 +514,16 @@ export interface NativePage {
336
514
  readonly cropBox?: PageObjectBounds;
337
515
  readonly trimBox?: PageObjectBounds;
338
516
  getText(): Promise<string>;
517
+ getCharacters(start?: number, count?: number): Promise<TextCharacter[]>;
339
518
  render(options?: PageRenderOptions): Promise<Buffer | void>;
340
519
  getObject(index: number): Promise<PageObject>;
341
520
  renderImage(index: number, options?: ImageRenderOptions): Promise<Buffer | void>;
342
521
  getLinks(): Promise<Link[]>;
343
522
  search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
344
523
  getAnnotations(): Promise<Annotation[]>;
524
+ getAnnotationAttachment(index: number, outputPath?: string): Promise<Buffer | undefined>;
345
525
  getFormFields(): Promise<FormField[]>;
526
+ getStructTree(): Promise<StructElement[]>;
346
527
  close(): void;
347
528
  }
348
529
  export interface NativeDocument {
@@ -352,6 +533,10 @@ export interface NativeDocument {
352
533
  getBookmarks(): Promise<Bookmark[]>;
353
534
  getAttachments(): Promise<Attachment[]>;
354
535
  getAttachment(index: number, outputPath?: string): Promise<Buffer | undefined>;
536
+ getSignatures(): Promise<Signature[]>;
537
+ getSignatureContents(index: number, outputPath?: string): Promise<Buffer | undefined>;
538
+ getJavaScriptActions(): Promise<JavaScriptAction[]>;
539
+ getNamedDestinations(): Promise<NamedDestination[]>;
355
540
  destroy(): void;
356
541
  }
357
542
  export interface SplitDocumentOptions {
@@ -370,6 +555,72 @@ export interface MergeDocumentsOptions {
370
555
  /** Write to this file path instead of returning a Buffer. */
371
556
  output?: string;
372
557
  }
558
+ export interface AssemblePagesOptions {
559
+ /** Write to this file path instead of returning a Buffer. */
560
+ output?: string;
561
+ /** Password for the source PDF (if encrypted). */
562
+ password?: string;
563
+ }
564
+ /**
565
+ * A file to embed with {@link addAttachments}.
566
+ *
567
+ * There is deliberately no `mimeType` or `description` field. The MIME type is
568
+ * `/Subtype` on the embedded-file stream and the description is `/Desc` on the
569
+ * filespec dictionary; PDFium's write API reaches neither in the bundled build,
570
+ * and accepting those values only to drop them silently would be worse than not
571
+ * offering them. Note this is an asymmetry with reading: `Attachment.mimeType`
572
+ * is reported when a PDF already carries it.
573
+ */
574
+ export interface AttachmentInput {
575
+ /**
576
+ * File name to store in the /EmbeddedFiles name tree, e.g. 'report.xml'.
577
+ * Must be non-empty and not already present in the document.
578
+ */
579
+ name: string;
580
+ /** File contents. */
581
+ data: Buffer;
582
+ /**
583
+ * Creation date as a PDF date string, e.g. 'D:20250101120000Z'. Defaults to
584
+ * the current time, so set it explicitly for reproducible output.
585
+ */
586
+ creationDate?: string;
587
+ /** Modification date as a PDF date string. */
588
+ modDate?: string;
589
+ }
590
+ export interface AddAttachmentsOptions {
591
+ /** Write to this file path instead of returning a Buffer. */
592
+ output?: string;
593
+ /** Password for the source PDF (if encrypted). */
594
+ password?: string;
595
+ }
596
+ export interface FlattenDocumentOptions {
597
+ /**
598
+ * Which appearance to bake in: `'display'` (default) or `'print'`. They
599
+ * differ for annotations whose appearance dictionary distinguishes the two —
600
+ * a watermark marked print-only, for instance.
601
+ */
602
+ usage?: 'display' | 'print';
603
+ /** Only flatten these page indices. Defaults to every page. */
604
+ pages?: number[];
605
+ /** Write to this file path instead of returning a Buffer. */
606
+ output?: string;
607
+ /** Password for the source PDF (if encrypted). */
608
+ password?: string;
609
+ }
610
+ export interface NUpPagesOptions {
611
+ /** Number of source pages placed side by side across each output page. */
612
+ columns: number;
613
+ /** Number of source pages stacked down each output page. */
614
+ rows: number;
615
+ /** Output page width in points. Defaults to the width of the first source page. */
616
+ width?: number;
617
+ /** Output page height in points. Defaults to the height of the first source page. */
618
+ height?: number;
619
+ /** Write to this file path instead of returning a Buffer. */
620
+ output?: string;
621
+ /** Password for the source PDF (if encrypted). */
622
+ password?: string;
623
+ }
373
624
  export interface NativeAddon {
374
625
  loadDocument(input: Buffer | string, password?: string): Promise<NativeDocument>;
375
626
  splitDocument(input: Buffer | string, splitAt: number[], options?: {
@@ -382,6 +633,10 @@ export interface NativeAddon {
382
633
  }>, options?: {
383
634
  output?: string;
384
635
  }): Promise<Buffer | undefined>;
636
+ assemblePages(input: Buffer | string, pages: number[], options?: AssemblePagesOptions): Promise<Buffer | undefined>;
637
+ nUpPages(input: Buffer | string, options: NUpPagesOptions): Promise<Buffer | undefined>;
638
+ addAttachments(input: Buffer | string, attachments: AttachmentInput[], options?: AddAttachmentsOptions): Promise<Buffer | undefined>;
639
+ flattenDocument(input: Buffer | string, options?: FlattenDocumentOptions): Promise<Buffer | undefined>;
385
640
  }
386
641
  export {};
387
642
  //# sourceMappingURL=types.d.ts.map