pdfium-native 0.2.0 → 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/lib/types.ts CHANGED
@@ -1,8 +1,3 @@
1
- export interface PageSize {
2
- width: number;
3
- height: number;
4
- }
5
-
6
1
  export interface PageRenderOptions {
7
2
  /** Scale factor (default: 1, meaning 72 DPI). Use 3–4 for print quality. */
8
3
  scale?: number;
@@ -16,39 +11,112 @@ export interface PageRenderOptions {
16
11
  quality?: number;
17
12
  /** Write to this file path instead of returning a Buffer. */
18
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;
19
24
  }
20
25
 
21
26
  export interface PageObjectBounds {
27
+ /** Left edge in page points. */
22
28
  left: number;
29
+ /** Bottom edge in page points. */
23
30
  bottom: number;
31
+ /** Right edge in page points. */
24
32
  right: number;
33
+ /** Top edge in page points. */
25
34
  top: number;
26
35
  }
27
36
 
28
37
  export interface RGBA {
38
+ /** Red channel (0–255). */
29
39
  r: number;
40
+ /** Green channel (0–255). */
30
41
  g: number;
42
+ /** Blue channel (0–255). */
31
43
  b: number;
44
+ /** Alpha channel (0–255, where 255 is fully opaque). */
32
45
  a: number;
33
46
  }
34
47
 
35
48
  interface BasePageObject {
49
+ /** Bounding box in page coordinates (points). */
36
50
  bounds: PageObjectBounds;
51
+ /** Fill color, or null if none. */
37
52
  fillColor: RGBA | null;
53
+ /** Stroke color, or null if none. */
38
54
  strokeColor: RGBA | null;
39
55
  }
40
56
 
57
+ export type TextRenderMode =
58
+ | 'fill'
59
+ | 'stroke'
60
+ | 'fillStroke'
61
+ | 'invisible'
62
+ | 'fillClip'
63
+ | 'strokeClip'
64
+ | 'fillStrokeClip'
65
+ | 'clip'
66
+ | 'unknown';
67
+
41
68
  export interface TextPageObject extends BasePageObject {
42
69
  type: 'text';
70
+ /** The text content of this object. */
43
71
  text: string;
72
+ /** Font size in points. */
44
73
  fontSize: number;
74
+ /** PostScript name of the font. */
45
75
  fontName: string;
76
+ /** Font weight (e.g. 400 = normal, 700 = bold). Absent if unavailable. */
77
+ fontWeight?: number;
78
+ /** Italic angle in degrees counterclockwise from vertical. Negative means right-sloping. */
79
+ italicAngle?: number;
80
+ /** Text render mode (e.g. 'fill', 'stroke', 'fillStroke'). */
81
+ renderMode?: TextRenderMode;
82
+ /** Font family name. */
83
+ fontFamily?: string;
84
+ /** Whether the font is embedded in the PDF. */
85
+ isEmbedded?: boolean;
86
+ /** Raw PDF font descriptor flags bitmask (see PDF spec Table 123). */
87
+ fontFlags?: number;
46
88
  }
47
89
 
90
+ export type ImageColorspace =
91
+ | 'deviceGray'
92
+ | 'deviceRGB'
93
+ | 'deviceCMYK'
94
+ | 'calGray'
95
+ | 'calRGB'
96
+ | 'lab'
97
+ | 'iccBased'
98
+ | 'separation'
99
+ | 'deviceN'
100
+ | 'indexed'
101
+ | 'pattern'
102
+ | 'unknown';
103
+
48
104
  export interface ImagePageObject extends BasePageObject {
49
105
  type: 'image';
106
+ /** Intrinsic image width in pixels. */
50
107
  imageWidth: number;
108
+ /** Intrinsic image height in pixels. */
51
109
  imageHeight: number;
110
+ /** Horizontal DPI of the image. */
111
+ horizontalDpi?: number;
112
+ /** Vertical DPI of the image. */
113
+ verticalDpi?: number;
114
+ /** Number of bits per pixel. */
115
+ bitsPerPixel?: number;
116
+ /** Image color space (e.g. 'deviceRGB', 'deviceCMYK'). */
117
+ colorspace?: ImageColorspace;
118
+ /** Compression filters applied to the image (e.g. 'FlateDecode', 'DCTDecode'). */
119
+ filters?: string[];
52
120
  }
53
121
 
54
122
  export interface OtherPageObject extends BasePageObject {
@@ -56,23 +124,35 @@ export interface OtherPageObject extends BasePageObject {
56
124
  }
57
125
 
58
126
  export type PageObject = TextPageObject | ImagePageObject | OtherPageObject;
59
- export type PageObjectType = PageObject['type'];
60
127
 
61
128
  export interface SearchOptions {
129
+ /** Match case when searching (default: false). */
62
130
  caseSensitive?: boolean;
131
+ /** Only match whole words (default: false). */
63
132
  wholeWord?: boolean;
133
+ /** Allow overlapping matches (default: false). */
134
+ consecutive?: boolean;
64
135
  }
65
136
 
66
137
  export interface SearchMatch {
138
+ /** 0-based character index where the match starts. */
67
139
  charIndex: number;
140
+ /** Number of characters in the match. */
68
141
  length: number;
142
+ /** The actual matched text from the page. */
143
+ matchedText?: string;
144
+ /** Bounding rectangles covering the matched text. */
69
145
  rects: SearchRect[];
70
146
  }
71
147
 
72
148
  export interface SearchRect {
149
+ /** Left edge in page points. */
73
150
  left: number;
151
+ /** Top edge in page points. */
74
152
  top: number;
153
+ /** Right edge in page points. */
75
154
  right: number;
155
+ /** Bottom edge in page points. */
76
156
  bottom: number;
77
157
  }
78
158
 
@@ -83,46 +163,210 @@ export type AnnotationType =
83
163
  | 'line'
84
164
  | 'square'
85
165
  | 'circle'
166
+ | 'polygon'
167
+ | 'polyline'
86
168
  | 'highlight'
87
169
  | 'underline'
88
170
  | 'squiggly'
89
171
  | 'strikeout'
90
172
  | 'stamp'
173
+ | 'caret'
91
174
  | 'ink'
92
175
  | 'popup'
176
+ | 'fileattachment'
177
+ | 'sound'
93
178
  | 'widget'
94
179
  | 'redact'
180
+ | 'watermark'
95
181
  | 'unknown';
96
182
 
183
+ export interface AnnotationBorder {
184
+ /** Horizontal corner radius. */
185
+ horizontalRadius: number;
186
+ /** Vertical corner radius. */
187
+ verticalRadius: number;
188
+ /** Border width in points. */
189
+ width: number;
190
+ }
191
+
192
+ export interface QuadPoints {
193
+ /** Top-left X. */
194
+ x1: number;
195
+ /** Top-left Y. */
196
+ y1: number;
197
+ /** Top-right X. */
198
+ x2: number;
199
+ /** Top-right Y. */
200
+ y2: number;
201
+ /** Bottom-left X. */
202
+ x3: number;
203
+ /** Bottom-left Y. */
204
+ y3: number;
205
+ /** Bottom-right X. */
206
+ x4: number;
207
+ /** Bottom-right Y. */
208
+ y4: number;
209
+ }
210
+
97
211
  export interface Annotation {
212
+ /** Annotation subtype (e.g. 'highlight', 'text', 'link'). */
98
213
  type: AnnotationType;
214
+ /** Bounding box in page coordinates, if available. */
99
215
  bounds?: PageObjectBounds;
216
+ /** Text contents of the annotation. */
100
217
  contents: string;
218
+ /** Annotation color, or null if none. */
101
219
  color: RGBA | null;
220
+ /** Interior (fill) color for markup annotations. */
221
+ interiorColor?: RGBA;
222
+ /** Author of the annotation. */
223
+ author: string;
224
+ /** Subject of the annotation. */
225
+ subject: string;
226
+ /** Creation date as a PDF date string (e.g. "D:20250328..."). */
227
+ creationDate: string;
228
+ /** Modification date as a PDF date string. */
229
+ modDate: string;
230
+ /** Raw annotation flags bitmask (see PDF spec Table 165). */
231
+ flags: number;
232
+ /** Border style of the annotation. */
233
+ border?: AnnotationBorder;
234
+ /** Quad points for text markup annotations (highlight, underline, etc.). */
235
+ quadPoints?: QuadPoints[];
236
+ }
237
+
238
+ export type LinkActionType = 'goto' | 'remoteGoto' | 'uri' | 'launch' | 'embeddedGoto' | 'unknown';
239
+
240
+ export type FormFieldType =
241
+ | 'pushButton'
242
+ | 'checkbox'
243
+ | 'radioButton'
244
+ | 'comboBox'
245
+ | 'listBox'
246
+ | 'textField'
247
+ | 'signature'
248
+ | 'unknown';
249
+
250
+ export interface FormFieldOption {
251
+ /** Display label for this option. */
252
+ label: string;
253
+ /** Whether this option is currently selected. */
254
+ isSelected: boolean;
255
+ }
256
+
257
+ export interface FormField {
258
+ /** Form field type. */
259
+ type: FormFieldType;
260
+ /** Fully qualified field name. */
261
+ name: string;
262
+ /** Current field value. */
263
+ value: string;
264
+ /** Alternate (tooltip) name, if set. */
265
+ alternateName?: string;
266
+ /** Export value for checkboxes and radio buttons. */
267
+ exportValue?: string;
268
+ /** Raw form field flags bitmask. */
269
+ flags: number;
270
+ /** Bounding box in page coordinates, if available. */
271
+ bounds?: PageObjectBounds;
272
+ /** Whether the field is checked (checkbox/radio only). */
273
+ isChecked: boolean;
274
+ /** Available options for combo box and list box fields. */
275
+ options?: FormFieldOption[];
102
276
  }
103
277
 
104
278
  export interface Link {
279
+ /** Bounding box in page coordinates, if available. */
105
280
  bounds?: PageObjectBounds;
281
+ /** External URL target, if this is a URI link. */
106
282
  url?: string;
283
+ /** Target page index for internal (goto) links. */
107
284
  pageIndex?: number;
285
+ /** The type of action this link performs. */
286
+ actionType?: LinkActionType;
287
+ /** Destination X coordinate (for internal links). */
288
+ destX?: number;
289
+ /** Destination Y coordinate (for internal links). */
290
+ destY?: number;
291
+ /** Destination zoom level (for internal links). */
292
+ destZoom?: number;
293
+ /** File path for remote goto or launch actions. */
294
+ filePath?: string;
108
295
  }
109
296
 
110
297
  export interface Bookmark {
298
+ /** Display title of the bookmark. */
111
299
  title: string;
300
+ /** Target page index, if the bookmark points to a page. */
112
301
  pageIndex?: number;
302
+ /** Whether this bookmark node is initially open (expanded) in the viewer. */
303
+ open: boolean;
304
+ /** The type of action this bookmark performs. */
305
+ actionType?: LinkActionType;
306
+ /** External URL target for URI bookmarks. */
307
+ url?: string;
308
+ /** Destination X coordinate. */
309
+ destX?: number;
310
+ /** Destination Y coordinate. */
311
+ destY?: number;
312
+ /** Destination zoom level. */
313
+ destZoom?: number;
314
+ /** Child bookmarks forming a tree. */
113
315
  children?: Bookmark[];
114
316
  }
115
317
 
318
+ export interface DocumentPermissions {
319
+ /** Printing the document. */
320
+ print: boolean;
321
+ /** Modifying document contents. */
322
+ modify: boolean;
323
+ /** Copying or extracting text and graphics. */
324
+ copy: boolean;
325
+ /** Adding or modifying annotations. */
326
+ annotate: boolean;
327
+ /** Filling in form fields. */
328
+ fillForms: boolean;
329
+ /** Extracting text and graphics for accessibility. */
330
+ extractForAccessibility: boolean;
331
+ /** Assembling the document (insert, rotate, delete pages). */
332
+ assemble: boolean;
333
+ /** High-resolution printing. */
334
+ printHighQuality: boolean;
335
+ }
336
+
116
337
  export interface DocumentMetadata {
338
+ /** Document title. */
117
339
  title: string;
340
+ /** Document author. */
118
341
  author: string;
342
+ /** Document subject. */
119
343
  subject: string;
344
+ /** Document keywords. */
120
345
  keywords: string;
346
+ /** Application that created the original document. */
121
347
  creator: string;
348
+ /** Application that produced the PDF. */
122
349
  producer: string;
350
+ /** Creation date as a PDF date string. */
123
351
  creationDate: string;
352
+ /** Last modification date as a PDF date string. */
124
353
  modDate: string;
354
+ /** PDF version as an integer (e.g. 17 for PDF 1.7). */
125
355
  pdfVersion: number;
356
+ /** Document permission flags. All true if unprotected. */
357
+ permissions: DocumentPermissions;
358
+ /** Whether the PDF is a tagged PDF (structured content). */
359
+ isTagged: boolean;
360
+ /** Document language (e.g. 'en-US'). Empty string if not set. */
361
+ language: string;
362
+ /** Number of digital signatures in the document. */
363
+ signatureCount: number;
364
+ /** Number of file attachments in the document. */
365
+ attachmentCount: number;
366
+ /** Permanent file identifier (hex string). */
367
+ permanentId?: string;
368
+ /** Changing file identifier (hex string, updated on each save). */
369
+ changingId?: string;
126
370
  }
127
371
 
128
372
  // native addon bindings (internal)
@@ -130,14 +374,19 @@ export interface NativePage {
130
374
  readonly number: number;
131
375
  readonly width: number;
132
376
  readonly height: number;
133
- readonly size: PageSize;
134
377
  readonly objectCount: number;
378
+ readonly rotation: number;
379
+ readonly hasTransparency: boolean;
380
+ readonly label?: string;
381
+ readonly cropBox?: PageObjectBounds;
382
+ readonly trimBox?: PageObjectBounds;
135
383
  getText(): Promise<string>;
136
384
  render(options?: PageRenderOptions): Promise<Buffer | void>;
137
385
  getObject(index: number): Promise<PageObject>;
138
386
  getLinks(): Promise<Link[]>;
139
387
  search(text: string, options?: SearchOptions): Promise<SearchMatch[]>;
140
388
  getAnnotations(): Promise<Annotation[]>;
389
+ getFormFields(): Promise<FormField[]>;
141
390
  close(): void;
142
391
  }
143
392
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfium-native",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "description": "Native Node.js bindings for PDFium",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,9 +13,18 @@
13
13
  "native",
14
14
  "render",
15
15
  "text-extraction",
16
- "ocr",
17
16
  "node-addon",
18
- "napi"
17
+ "napi",
18
+ "pdf-parser",
19
+ "pdf-reader",
20
+ "pdf-to-text",
21
+ "pdf-to-image",
22
+ "pdf-render",
23
+ "extract-text",
24
+ "search",
25
+ "annotations",
26
+ "bookmarks",
27
+ "chromium"
19
28
  ],
20
29
  "main": "dist/index.js",
21
30
  "types": "dist/index.d.ts",
@@ -36,6 +45,10 @@
36
45
  "type": "git",
37
46
  "url": "git+https://github.com/xonaman/nodejs-pdfium-native.git"
38
47
  },
48
+ "homepage": "https://github.com/xonaman/nodejs-pdfium-native#readme",
49
+ "bugs": {
50
+ "url": "https://github.com/xonaman/nodejs-pdfium-native/issues"
51
+ },
39
52
  "publishConfig": {
40
53
  "access": "public"
41
54
  },
@@ -11,15 +11,28 @@ if (!existsSync(nodeFile)) {
11
11
  process.exit(1);
12
12
  }
13
13
 
14
+ /** Strip debug symbols from a binary. */
15
+ function strip(file) {
16
+ // macOS: -S strips debug symbols only (preserves load commands in dylibs)
17
+ // Linux: -s strips all symbols
18
+ const args = process.platform === 'darwin' ? ['-S'] : ['-s'];
19
+ try {
20
+ execFileSync('strip', [...args, file], { stdio: 'inherit' });
21
+ console.log(`Stripped ${file.split('/').pop()}`);
22
+ } catch {
23
+ console.warn(`strip failed for ${file.split('/').pop()} — continuing`);
24
+ }
25
+ }
26
+
14
27
  // on Windows, binding.gyp copies the DLL via "copies" — nothing else to do
15
28
  if (process.platform === 'win32') {
16
29
  const dll = join(outDir, 'pdfium.dll');
17
- if (existsSync(dll)) {
18
- console.log('pdfium.dll already in build/Release/ (copied by node-gyp).');
19
- } else {
30
+ if (!existsSync(dll)) {
20
31
  console.error('pdfium.dll not found in build/Release/ — check binding.gyp copies.');
21
32
  process.exit(1);
22
33
  }
34
+ console.log('pdfium.dll already in build/Release/ (copied by node-gyp).');
35
+ strip(nodeFile);
23
36
  console.log('Bundle complete.');
24
37
  process.exit(0);
25
38
  }
@@ -63,4 +76,12 @@ if (process.platform === 'darwin') {
63
76
  }
64
77
  }
65
78
 
79
+ // strip debug symbols from shared libraries on Linux to reduce binary size
80
+ // pdfium.node is stripped at link time via -Wl,-S in binding.gyp
81
+ if (process.platform === 'linux') {
82
+ for (const lib of libs) {
83
+ strip(join(outDir, lib));
84
+ }
85
+ }
86
+
66
87
  console.log('Bundle complete.');
@@ -40,7 +40,8 @@ const TARGETS = {
40
40
  };
41
41
 
42
42
  const platform = process.platform;
43
- const arch = process.arch;
43
+ // support cross-compilation via npm_config_arch (e.g. win32 x64 → arm64)
44
+ const arch = process.env.npm_config_arch || process.arch;
44
45
  const musl = isMusl();
45
46
  const key = musl ? `${platform}-musl-${arch}` : `${platform}-${arch}`;
46
47
  const target = TARGETS[key];