pdfium-native 0.2.2 β†’ 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,24 +48,24 @@ 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
- - πŸ”— Read annotations, bookmarks, and links from existing PDFs
51
+ - πŸ”— Read annotations, bookmarks, links, and form fields from existing PDFs
52
52
 
53
53
  ### πŸ“Š How it compares
54
54
 
55
- | | **pdfium-native** | @hyzyla/pdfium | pdfjs-dist | pdf-parse | pdf2json |
56
- | ------------------- | ----------------------- | ------------------------- | ----------------- | -------------- | ------------------- |
57
- | Engine | PDFium (C++ addon) | PDFium (WASM) | pdf.js (JS) | pdf.js (JS) | pdf.js fork (JS) |
58
- | Rendering | βœ… JPEG/PNG built-in | ⚠️ Raw bitmap (BYO sharp) | ⚠️ Canvas/browser | ❌ | ❌ |
59
- | Text extraction | βœ… | ❌ | βœ… | βœ… | βœ… (structured) |
60
- | Search (with rects) | βœ… | ❌ | ⚠️ Manual | ❌ | ❌ |
61
- | Annotations | βœ… | ❌ | ⚠️ Partial | ❌ | ❌ |
62
- | Bookmarks | βœ… | ❌ | βœ… | ❌ | ❌ |
63
- | Links | βœ… | ❌ | βœ… | ❌ | ❌ |
64
- | Form fields | ❌ | ❌ | βœ… | ❌ | βœ… |
65
- | Async I/O | βœ… libuv workers | ❌ Sync (WASM) | ❌ Main thread | ❌ Main thread | ⚠️ Events / streams |
66
- | Environment | Node.js | Node.js + browser | Node.js + browser | Node.js | Node.js |
67
- | Dependencies | NoneΒΉ | None (WASM bundled) | None | pdf.js | None (since v3) |
68
- | Platforms | macOS / Linux / Windows | Any (WASM) | Any | Any | Any |
55
+ | | **pdfium-native** | @hyzyla/pdfium | pdfjs-dist |
56
+ | ------------------- | ----------------------- | ------------------------- | ----------------- |
57
+ | Engine | PDFium (C++ addon) | PDFium (WASM) | pdf.js (JS) |
58
+ | Rendering | βœ… JPEG/PNG built-in | ⚠️ Raw bitmap (BYO sharp) | ⚠️ Canvas/browser |
59
+ | Text extraction | βœ… | ❌ | βœ… |
60
+ | Search (with rects) | βœ… | ❌ | ⚠️ Manual |
61
+ | Annotations | βœ… | ❌ | ⚠️ Partial |
62
+ | Bookmarks | βœ… | ❌ | βœ… |
63
+ | Links | βœ… | ❌ | βœ… |
64
+ | Form fields | βœ… | ❌ | βœ… |
65
+ | Async I/O | βœ… libuv workers | ❌ Sync (WASM) | ❌ Main thread |
66
+ | Environment | Node.js | Node.js + browser | Node.js + browser |
67
+ | Dependencies | NoneΒΉ | None (WASM bundled) | None |
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
 
@@ -130,6 +130,12 @@ Returns the bookmark/outline tree. Returns `Promise<Bookmark[]>`.
130
130
  interface Bookmark {
131
131
  title: string;
132
132
  pageIndex?: number;
133
+ open: boolean; // whether the node is initially expanded
134
+ actionType?: 'goto' | 'remoteGoto' | 'uri' | 'launch' | 'embeddedGoto';
135
+ url?: string; // external URL for URI bookmarks
136
+ destX?: number; // destination X coordinate
137
+ destY?: number; // destination Y coordinate
138
+ destZoom?: number; // destination zoom level
133
139
  children?: Bookmark[];
134
140
  }
135
141
  ```
@@ -142,13 +148,17 @@ Closes the document and frees all native resources. Must be called when done.
142
148
 
143
149
  ### PDFiumPage
144
150
 
145
- | Property | Type | Description |
146
- | ------------- | ------------------- | --------------------------------------------------- |
147
- | `width` | `number` | Page width in points (1 pt = 1/72 inch). |
148
- | `height` | `number` | Page height in points. |
149
- | `size` | `{ width, height }` | Page dimensions. |
150
- | `number` | `number` | 0-based page index. |
151
- | `objectCount` | `number` | Number of page objects (text, images, paths, etc.). |
151
+ | Property | Type | Description |
152
+ | ----------------- | ------------------- | --------------------------------------------------- |
153
+ | `width` | `number` | Page width in points (1 pt = 1/72 inch). |
154
+ | `height` | `number` | Page height in points. |
155
+ | `number` | `number` | 0-based page index. |
156
+ | `objectCount` | `number` | Number of page objects (text, images, paths, etc.). |
157
+ | `rotation` | `number` | Page rotation: 0, 1 (90Β° CW), 2 (180Β°), 3 (270Β°). |
158
+ | `hasTransparency` | `boolean` | Whether the page has transparency. |
159
+ | `label` | `string?` | Page label (e.g. 'i', 'ii', '1'). |
160
+ | `cropBox` | `PageObjectBounds?` | Crop box (visible region), if set. |
161
+ | `trimBox` | `PageObjectBounds?` | Trim box (intended finished size), if set. |
152
162
 
153
163
  #### `getText()`
154
164
 
@@ -166,6 +176,11 @@ interface PageRenderOptions {
166
176
  format?: 'jpeg' | 'png'; // default: 'jpeg'
167
177
  quality?: number; // JPEG quality 1–100 (default: 100)
168
178
  output?: string; // write to file instead of returning a Buffer
179
+ rotation?: 0 | 1 | 2 | 3; // 0=none, 1=90Β° CW, 2=180Β°, 3=270Β° CW
180
+ transparent?: boolean; // transparent background (PNG only, default: false)
181
+ renderAnnotations?: boolean; // render annotations (default: true)
182
+ grayscale?: boolean; // render in grayscale
183
+ lcdText?: boolean; // LCD-optimized sub-pixel text rendering
169
184
  }
170
185
  ```
171
186
 
@@ -181,8 +196,10 @@ type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
181
196
  // fillColor: { r, g, b, a } | null
182
197
  // strokeColor: { r, g, b, a } | null
183
198
 
184
- // type: 'text' adds: text, fontSize, fontName
185
- // type: 'image' adds: imageWidth, imageHeight
199
+ // type: 'text' adds: text, fontSize, fontName, fontWeight?, italicAngle?,
200
+ // renderMode?, fontFamily?, isEmbedded?, fontFlags?
201
+ // type: 'image' adds: imageWidth, imageHeight, horizontalDpi?, verticalDpi?,
202
+ // bitsPerPixel?, colorspace?, filters?
186
203
  // type: 'path' | 'shading' | 'form' | 'unknown'
187
204
  ```
188
205
 
@@ -195,6 +212,11 @@ interface Link {
195
212
  bounds?: { left; bottom; right; top };
196
213
  url?: string; // external URL
197
214
  pageIndex?: number; // internal link target
215
+ actionType?: 'goto' | 'remoteGoto' | 'uri' | 'launch' | 'embeddedGoto' | 'unknown';
216
+ destX?: number; // destination X coordinate
217
+ destY?: number; // destination Y coordinate
218
+ destZoom?: number; // destination zoom level
219
+ filePath?: string; // file path for remote goto / launch actions
198
220
  }
199
221
  ```
200
222
 
@@ -203,8 +225,12 @@ interface Link {
203
225
  Searches for text on the page. Returns `Promise<SearchMatch[]>` with character positions and bounding rectangles.
204
226
 
205
227
  ```typescript
206
- const matches = await page.search('invoice', { caseSensitive: true, wholeWord: false });
207
- // [{ charIndex: 42, length: 7, rects: [{ left, top, right, bottom }] }]
228
+ const matches = await page.search('invoice', {
229
+ caseSensitive: true,
230
+ wholeWord: false,
231
+ consecutive: false,
232
+ });
233
+ // [{ charIndex: 42, length: 7, matchedText: 'invoice', rects: [{ left, top, right, bottom }] }]
208
234
  ```
209
235
 
210
236
  #### `getAnnotations()`
@@ -217,9 +243,54 @@ interface Annotation {
217
243
  bounds?: { left; bottom; right; top };
218
244
  contents: string;
219
245
  color: { r; g; b; a } | null;
246
+ interiorColor?: { r; g; b; a }; // fill color for markup annotations
247
+ author: string; // annotation author
248
+ subject: string; // annotation subject
249
+ creationDate: string; // PDF date string (e.g. "D:20250101120000Z")
250
+ modDate: string; // modification date
251
+ flags: number; // annotation flags bitmask (PDF spec Table 165)
252
+ border?: { horizontalRadius; verticalRadius; width };
253
+ quadPoints?: Array<{ x1; y1; x2; y2; x3; y3; x4; y4 }>;
220
254
  }
221
255
  ```
222
256
 
257
+ #### `getFormFields()`
258
+
259
+ Returns all form fields on the page. Returns `Promise<FormField[]>`.
260
+
261
+ ```typescript
262
+ interface FormField {
263
+ type:
264
+ | 'unknown'
265
+ | 'pushButton'
266
+ | 'checkbox'
267
+ | 'radioButton'
268
+ | 'comboBox'
269
+ | 'listBox'
270
+ | 'textField'
271
+ | 'signature';
272
+ name: string; // field name
273
+ value: string; // current value
274
+ alternateName?: string; // tooltip / alternate field name
275
+ exportValue?: string; // export value (checkboxes / radio buttons)
276
+ flags: number; // field flags bitmask
277
+ bounds?: { left; bottom; right; top };
278
+ isChecked: boolean; // whether checkbox / radio is checked
279
+ options?: FormFieldOption[]; // options for combo box / list box
280
+ }
281
+
282
+ interface FormFieldOption {
283
+ label: string;
284
+ isSelected: boolean;
285
+ }
286
+ ```
287
+
288
+ ```typescript
289
+ const fields = await page.getFormFields();
290
+ const textFields = fields.filter((f) => f.type === 'textField');
291
+ const checked = fields.filter((f) => f.isChecked);
292
+ ```
293
+
223
294
  #### `close()`
224
295
 
225
296
  Closes the page and frees resources. Must be called when done with the page.
@@ -239,6 +310,22 @@ interface DocumentMetadata {
239
310
  creationDate: string;
240
311
  modDate: string;
241
312
  pdfVersion: number; // e.g. 17 for PDF 1.7
313
+ permissions: {
314
+ print: boolean;
315
+ modify: boolean;
316
+ copy: boolean;
317
+ annotate: boolean;
318
+ fillForms: boolean;
319
+ extractForAccessibility: boolean;
320
+ assemble: boolean;
321
+ printHighQuality: boolean;
322
+ };
323
+ isTagged: boolean; // whether the PDF is a tagged PDF
324
+ language: string; // document language (e.g. 'en-US')
325
+ signatureCount: number; // number of digital signatures
326
+ attachmentCount: number; // number of file attachments
327
+ permanentId?: string; // permanent file identifier (hex)
328
+ changingId?: string; // changing file identifier (hex)
242
329
  }
243
330
  ```
244
331
 
package/dist/index.d.ts CHANGED
@@ -7,5 +7,5 @@ export declare function loadDocument(input: PdfInput, password?: string): Promis
7
7
  export { PDFiumDocument } from './document.js';
8
8
  export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
9
9
  export { PDFiumPage } from './page.js';
10
- export type { Annotation, AnnotationType, Bookmark, DocumentMetadata, ImagePageObject, Link, OtherPageObject, PageObject, PageObjectBounds, PageObjectType, PageRenderOptions, PageSize, RGBA, SearchMatch, SearchOptions, SearchRect, TextPageObject, } from './types.js';
10
+ export type { Annotation, AnnotationBorder, AnnotationType, Bookmark, DocumentMetadata, DocumentPermissions, FormField, FormFieldOption, FormFieldType, ImageColorspace, ImagePageObject, Link, LinkActionType, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, TextPageObject, TextRenderMode, } from './types.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAchC;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAM9F;AAED,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;AACvC,YAAY,EACV,UAAU,EACV,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAchC;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAM9F;AAED,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;AACvC,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,IAAI,EACJ,cAAc,EACd,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC"}
package/dist/page.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Annotation, Link, NativePage, PageObject, PageRenderOptions, PageSize, SearchMatch, SearchOptions } from './types.js';
1
+ import type { Annotation, FormField, Link, NativePage, PageObject, PageObjectBounds, PageRenderOptions, SearchMatch, SearchOptions } from './types.js';
2
2
  /**
3
3
  * A page in a PDF document.
4
4
  */
@@ -8,12 +8,20 @@ export declare class PDFiumPage {
8
8
  readonly width: number;
9
9
  /** Page height in points (1 pt = 1/72 inch). */
10
10
  readonly height: number;
11
- /** Page dimensions in points. */
12
- readonly size: PageSize;
13
11
  /** 0-based page index. */
14
12
  readonly number: number;
15
13
  /** Number of page objects (text spans, paths, images, etc.). */
16
14
  readonly objectCount: number;
15
+ /** Page rotation: 0 = none, 1 = 90Β° CW, 2 = 180Β°, 3 = 270Β° CW. */
16
+ readonly rotation: number;
17
+ /** Whether the page has transparency. */
18
+ readonly hasTransparency: boolean;
19
+ /** Page label (e.g. 'i', 'ii', '1', '2'). Only set if the document defines page labels. */
20
+ readonly label?: string;
21
+ /** Crop box (visible region), if explicitly set. */
22
+ readonly cropBox?: PageObjectBounds;
23
+ /** Trim box (intended finished page size), if explicitly set. */
24
+ readonly trimBox?: PageObjectBounds;
17
25
  /** @internal */
18
26
  constructor(native: NativePage);
19
27
  /** Extracts all text from the page. */
@@ -36,5 +44,7 @@ export declare class PDFiumPage {
36
44
  search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
37
45
  /** Returns all annotations on the page. */
38
46
  getAnnotations(): Promise<Annotation[]>;
47
+ /** Returns all form fields on the page. */
48
+ getFormFields(): Promise<FormField[]>;
39
49
  }
40
50
  //# sourceMappingURL=page.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,IAAI,EACJ,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,UAAU;IAaT,OAAO,CAAC,MAAM;IAZ1B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gBAAgB;gBACI,MAAM,EAAE,UAAU;IAQtC,uCAAuC;IACvC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,kCAAkC;IAClC,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACtE,iEAAiE;IACjE,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB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AAiE;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;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACtE,iEAAiE;IACjE,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKpD,uEAAuE;IACvE,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI7C,wEAAwE;IACjE,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IAM5C,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAIb,qCAAqC;IACrC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI3B,wFAAwF;IACxF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIrE,2CAA2C;IAC3C,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAIvC,2CAA2C;IAC3C,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAGtC"}
package/dist/page.js CHANGED
@@ -7,20 +7,35 @@ export class PDFiumPage {
7
7
  width;
8
8
  /** Page height in points (1 pt = 1/72 inch). */
9
9
  height;
10
- /** Page dimensions in points. */
11
- size;
12
10
  /** 0-based page index. */
13
11
  number;
14
12
  /** Number of page objects (text spans, paths, images, etc.). */
15
13
  objectCount;
14
+ /** Page rotation: 0 = none, 1 = 90Β° CW, 2 = 180Β°, 3 = 270Β° CW. */
15
+ rotation;
16
+ /** Whether the page has transparency. */
17
+ hasTransparency;
18
+ /** Page label (e.g. 'i', 'ii', '1', '2'). Only set if the document defines page labels. */
19
+ label;
20
+ /** Crop box (visible region), if explicitly set. */
21
+ cropBox;
22
+ /** Trim box (intended finished page size), if explicitly set. */
23
+ trimBox;
16
24
  /** @internal */
17
25
  constructor(native) {
18
26
  this.native = native;
19
27
  this.width = native.width;
20
28
  this.height = native.height;
21
- this.size = native.size;
22
29
  this.number = native.number;
23
30
  this.objectCount = native.objectCount;
31
+ this.rotation = native.rotation;
32
+ this.hasTransparency = native.hasTransparency;
33
+ if (native.label !== undefined)
34
+ this.label = native.label;
35
+ if (native.cropBox !== undefined)
36
+ this.cropBox = native.cropBox;
37
+ if (native.trimBox !== undefined)
38
+ this.trimBox = native.trimBox;
24
39
  }
25
40
  /** Extracts all text from the page. */
26
41
  getText() {
@@ -55,5 +70,9 @@ export class PDFiumPage {
55
70
  getAnnotations() {
56
71
  return this.native.getAnnotations();
57
72
  }
73
+ /** Returns all form fields on the page. */
74
+ getFormFields() {
75
+ return this.native.getFormFields();
76
+ }
58
77
  }
59
78
  //# sourceMappingURL=page.js.map
package/dist/page.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"page.js","sourceRoot":"","sources":["../lib/page.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,UAAU;IAaD;IAZpB,+CAA+C;IACtC,KAAK,CAAS;IACvB,gDAAgD;IACvC,MAAM,CAAS;IACxB,iCAAiC;IACxB,IAAI,CAAW;IACxB,0BAA0B;IACjB,MAAM,CAAS;IACxB,gEAAgE;IACvD,WAAW,CAAS;IAE7B,gBAAgB;IAChB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QACpC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAA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AAC,OAAO;QACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,qCAAqC;IACrC,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED,wFAAwF;IACxF,MAAM,CAAC,IAAY,EAAE,OAAuB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,2CAA2C;IAC3C,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAED,2CAA2C;IAC3C,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;IACrC,CAAC;CACF"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- export interface PageSize {
2
- width: number;
3
- height: number;
4
- }
5
1
  export interface PageRenderOptions {
6
2
  /** Scale factor (default: 1, meaning 72 DPI). Use 3–4 for print quality. */
7
3
  scale?: number;
@@ -15,95 +11,305 @@ export interface PageRenderOptions {
15
11
  quality?: number;
16
12
  /** Write to this file path instead of returning a Buffer. */
17
13
  output?: string;
14
+ /** Page rotation: 0 = none, 1 = 90Β° CW, 2 = 180Β°, 3 = 270Β° CW. */
15
+ rotation?: 0 | 1 | 2 | 3;
16
+ /** Render with transparent background instead of white (PNG only). */
17
+ transparent?: boolean;
18
+ /** Whether to render annotations (default: true). */
19
+ renderAnnotations?: boolean;
20
+ /** Render in grayscale. */
21
+ grayscale?: boolean;
22
+ /** Enable LCD-optimized text rendering (sub-pixel anti-aliasing). */
23
+ lcdText?: boolean;
18
24
  }
19
25
  export interface PageObjectBounds {
26
+ /** Left edge in page points. */
20
27
  left: number;
28
+ /** Bottom edge in page points. */
21
29
  bottom: number;
30
+ /** Right edge in page points. */
22
31
  right: number;
32
+ /** Top edge in page points. */
23
33
  top: number;
24
34
  }
25
35
  export interface RGBA {
36
+ /** Red channel (0–255). */
26
37
  r: number;
38
+ /** Green channel (0–255). */
27
39
  g: number;
40
+ /** Blue channel (0–255). */
28
41
  b: number;
42
+ /** Alpha channel (0–255, where 255 is fully opaque). */
29
43
  a: number;
30
44
  }
31
45
  interface BasePageObject {
46
+ /** Bounding box in page coordinates (points). */
32
47
  bounds: PageObjectBounds;
48
+ /** Fill color, or null if none. */
33
49
  fillColor: RGBA | null;
50
+ /** Stroke color, or null if none. */
34
51
  strokeColor: RGBA | null;
35
52
  }
53
+ export type TextRenderMode = 'fill' | 'stroke' | 'fillStroke' | 'invisible' | 'fillClip' | 'strokeClip' | 'fillStrokeClip' | 'clip' | 'unknown';
36
54
  export interface TextPageObject extends BasePageObject {
37
55
  type: 'text';
56
+ /** The text content of this object. */
38
57
  text: string;
58
+ /** Font size in points. */
39
59
  fontSize: number;
60
+ /** PostScript name of the font. */
40
61
  fontName: string;
62
+ /** Font weight (e.g. 400 = normal, 700 = bold). Absent if unavailable. */
63
+ fontWeight?: number;
64
+ /** Italic angle in degrees counterclockwise from vertical. Negative means right-sloping. */
65
+ italicAngle?: number;
66
+ /** Text render mode (e.g. 'fill', 'stroke', 'fillStroke'). */
67
+ renderMode?: TextRenderMode;
68
+ /** Font family name. */
69
+ fontFamily?: string;
70
+ /** Whether the font is embedded in the PDF. */
71
+ isEmbedded?: boolean;
72
+ /** Raw PDF font descriptor flags bitmask (see PDF spec Table 123). */
73
+ fontFlags?: number;
41
74
  }
75
+ export type ImageColorspace = 'deviceGray' | 'deviceRGB' | 'deviceCMYK' | 'calGray' | 'calRGB' | 'lab' | 'iccBased' | 'separation' | 'deviceN' | 'indexed' | 'pattern' | 'unknown';
42
76
  export interface ImagePageObject extends BasePageObject {
43
77
  type: 'image';
78
+ /** Intrinsic image width in pixels. */
44
79
  imageWidth: number;
80
+ /** Intrinsic image height in pixels. */
45
81
  imageHeight: number;
82
+ /** Horizontal DPI of the image. */
83
+ horizontalDpi?: number;
84
+ /** Vertical DPI of the image. */
85
+ verticalDpi?: number;
86
+ /** Number of bits per pixel. */
87
+ bitsPerPixel?: number;
88
+ /** Image color space (e.g. 'deviceRGB', 'deviceCMYK'). */
89
+ colorspace?: ImageColorspace;
90
+ /** Compression filters applied to the image (e.g. 'FlateDecode', 'DCTDecode'). */
91
+ filters?: string[];
46
92
  }
47
93
  export interface OtherPageObject extends BasePageObject {
48
94
  type: 'path' | 'shading' | 'form' | 'unknown';
49
95
  }
50
96
  export type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
51
- export type PageObjectType = PageObject['type'];
52
97
  export interface SearchOptions {
98
+ /** Match case when searching (default: false). */
53
99
  caseSensitive?: boolean;
100
+ /** Only match whole words (default: false). */
54
101
  wholeWord?: boolean;
102
+ /** Allow overlapping matches (default: false). */
103
+ consecutive?: boolean;
55
104
  }
56
105
  export interface SearchMatch {
106
+ /** 0-based character index where the match starts. */
57
107
  charIndex: number;
108
+ /** Number of characters in the match. */
58
109
  length: number;
110
+ /** The actual matched text from the page. */
111
+ matchedText?: string;
112
+ /** Bounding rectangles covering the matched text. */
59
113
  rects: SearchRect[];
60
114
  }
61
115
  export interface SearchRect {
116
+ /** Left edge in page points. */
62
117
  left: number;
118
+ /** Top edge in page points. */
63
119
  top: number;
120
+ /** Right edge in page points. */
64
121
  right: number;
122
+ /** Bottom edge in page points. */
65
123
  bottom: number;
66
124
  }
67
- export type AnnotationType = 'text' | 'link' | 'freetext' | 'line' | 'square' | 'circle' | 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'stamp' | 'ink' | 'popup' | 'widget' | 'redact' | 'unknown';
125
+ export type AnnotationType = 'text' | 'link' | 'freetext' | 'line' | 'square' | 'circle' | 'polygon' | 'polyline' | 'highlight' | 'underline' | 'squiggly' | 'strikeout' | 'stamp' | 'caret' | 'ink' | 'popup' | 'fileattachment' | 'sound' | 'widget' | 'redact' | 'watermark' | 'unknown';
126
+ export interface AnnotationBorder {
127
+ /** Horizontal corner radius. */
128
+ horizontalRadius: number;
129
+ /** Vertical corner radius. */
130
+ verticalRadius: number;
131
+ /** Border width in points. */
132
+ width: number;
133
+ }
134
+ export interface QuadPoints {
135
+ /** Top-left X. */
136
+ x1: number;
137
+ /** Top-left Y. */
138
+ y1: number;
139
+ /** Top-right X. */
140
+ x2: number;
141
+ /** Top-right Y. */
142
+ y2: number;
143
+ /** Bottom-left X. */
144
+ x3: number;
145
+ /** Bottom-left Y. */
146
+ y3: number;
147
+ /** Bottom-right X. */
148
+ x4: number;
149
+ /** Bottom-right Y. */
150
+ y4: number;
151
+ }
68
152
  export interface Annotation {
153
+ /** Annotation subtype (e.g. 'highlight', 'text', 'link'). */
69
154
  type: AnnotationType;
155
+ /** Bounding box in page coordinates, if available. */
70
156
  bounds?: PageObjectBounds;
157
+ /** Text contents of the annotation. */
71
158
  contents: string;
159
+ /** Annotation color, or null if none. */
72
160
  color: RGBA | null;
161
+ /** Interior (fill) color for markup annotations. */
162
+ interiorColor?: RGBA;
163
+ /** Author of the annotation. */
164
+ author: string;
165
+ /** Subject of the annotation. */
166
+ subject: string;
167
+ /** Creation date as a PDF date string (e.g. "D:20250328..."). */
168
+ creationDate: string;
169
+ /** Modification date as a PDF date string. */
170
+ modDate: string;
171
+ /** Raw annotation flags bitmask (see PDF spec Table 165). */
172
+ flags: number;
173
+ /** Border style of the annotation. */
174
+ border?: AnnotationBorder;
175
+ /** Quad points for text markup annotations (highlight, underline, etc.). */
176
+ quadPoints?: QuadPoints[];
177
+ }
178
+ export type LinkActionType = 'goto' | 'remoteGoto' | 'uri' | 'launch' | 'embeddedGoto' | 'unknown';
179
+ export type FormFieldType = 'pushButton' | 'checkbox' | 'radioButton' | 'comboBox' | 'listBox' | 'textField' | 'signature' | 'unknown';
180
+ export interface FormFieldOption {
181
+ /** Display label for this option. */
182
+ label: string;
183
+ /** Whether this option is currently selected. */
184
+ isSelected: boolean;
185
+ }
186
+ export interface FormField {
187
+ /** Form field type. */
188
+ type: FormFieldType;
189
+ /** Fully qualified field name. */
190
+ name: string;
191
+ /** Current field value. */
192
+ value: string;
193
+ /** Alternate (tooltip) name, if set. */
194
+ alternateName?: string;
195
+ /** Export value for checkboxes and radio buttons. */
196
+ exportValue?: string;
197
+ /** Raw form field flags bitmask. */
198
+ flags: number;
199
+ /** Bounding box in page coordinates, if available. */
200
+ bounds?: PageObjectBounds;
201
+ /** Whether the field is checked (checkbox/radio only). */
202
+ isChecked: boolean;
203
+ /** Available options for combo box and list box fields. */
204
+ options?: FormFieldOption[];
73
205
  }
74
206
  export interface Link {
207
+ /** Bounding box in page coordinates, if available. */
75
208
  bounds?: PageObjectBounds;
209
+ /** External URL target, if this is a URI link. */
76
210
  url?: string;
211
+ /** Target page index for internal (goto) links. */
77
212
  pageIndex?: number;
213
+ /** The type of action this link performs. */
214
+ actionType?: LinkActionType;
215
+ /** Destination X coordinate (for internal links). */
216
+ destX?: number;
217
+ /** Destination Y coordinate (for internal links). */
218
+ destY?: number;
219
+ /** Destination zoom level (for internal links). */
220
+ destZoom?: number;
221
+ /** File path for remote goto or launch actions. */
222
+ filePath?: string;
78
223
  }
79
224
  export interface Bookmark {
225
+ /** Display title of the bookmark. */
80
226
  title: string;
227
+ /** Target page index, if the bookmark points to a page. */
81
228
  pageIndex?: number;
229
+ /** Whether this bookmark node is initially open (expanded) in the viewer. */
230
+ open: boolean;
231
+ /** The type of action this bookmark performs. */
232
+ actionType?: LinkActionType;
233
+ /** External URL target for URI bookmarks. */
234
+ url?: string;
235
+ /** Destination X coordinate. */
236
+ destX?: number;
237
+ /** Destination Y coordinate. */
238
+ destY?: number;
239
+ /** Destination zoom level. */
240
+ destZoom?: number;
241
+ /** Child bookmarks forming a tree. */
82
242
  children?: Bookmark[];
83
243
  }
244
+ export interface DocumentPermissions {
245
+ /** Printing the document. */
246
+ print: boolean;
247
+ /** Modifying document contents. */
248
+ modify: boolean;
249
+ /** Copying or extracting text and graphics. */
250
+ copy: boolean;
251
+ /** Adding or modifying annotations. */
252
+ annotate: boolean;
253
+ /** Filling in form fields. */
254
+ fillForms: boolean;
255
+ /** Extracting text and graphics for accessibility. */
256
+ extractForAccessibility: boolean;
257
+ /** Assembling the document (insert, rotate, delete pages). */
258
+ assemble: boolean;
259
+ /** High-resolution printing. */
260
+ printHighQuality: boolean;
261
+ }
84
262
  export interface DocumentMetadata {
263
+ /** Document title. */
85
264
  title: string;
265
+ /** Document author. */
86
266
  author: string;
267
+ /** Document subject. */
87
268
  subject: string;
269
+ /** Document keywords. */
88
270
  keywords: string;
271
+ /** Application that created the original document. */
89
272
  creator: string;
273
+ /** Application that produced the PDF. */
90
274
  producer: string;
275
+ /** Creation date as a PDF date string. */
91
276
  creationDate: string;
277
+ /** Last modification date as a PDF date string. */
92
278
  modDate: string;
279
+ /** PDF version as an integer (e.g. 17 for PDF 1.7). */
93
280
  pdfVersion: number;
281
+ /** Document permission flags. All true if unprotected. */
282
+ permissions: DocumentPermissions;
283
+ /** Whether the PDF is a tagged PDF (structured content). */
284
+ isTagged: boolean;
285
+ /** Document language (e.g. 'en-US'). Empty string if not set. */
286
+ language: string;
287
+ /** Number of digital signatures in the document. */
288
+ signatureCount: number;
289
+ /** Number of file attachments in the document. */
290
+ attachmentCount: number;
291
+ /** Permanent file identifier (hex string). */
292
+ permanentId?: string;
293
+ /** Changing file identifier (hex string, updated on each save). */
294
+ changingId?: string;
94
295
  }
95
296
  export interface NativePage {
96
297
  readonly number: number;
97
298
  readonly width: number;
98
299
  readonly height: number;
99
- readonly size: PageSize;
100
300
  readonly objectCount: number;
301
+ readonly rotation: number;
302
+ readonly hasTransparency: boolean;
303
+ readonly label?: string;
304
+ readonly cropBox?: PageObjectBounds;
305
+ readonly trimBox?: PageObjectBounds;
101
306
  getText(): Promise<string>;
102
307
  render(options?: PageRenderOptions): Promise<Buffer | void>;
103
308
  getObject(index: number): Promise<PageObject>;
104
309
  getLinks(): Promise<Link[]>;
105
310
  search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
106
311
  getAnnotations(): Promise<Annotation[]>;
312
+ getFormFields(): Promise<FormField[]>;
107
313
  close(): void;
108
314
  }
109
315
  export interface NativeDocument {