pdf-oxide 0.3.42 → 0.3.43

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/index.d.ts CHANGED
@@ -79,8 +79,28 @@ declare class PdfDocumentImpl {
79
79
  * export — exposed in TS for the first time as part of gap L.
80
80
  */
81
81
  estimateRenderTime(pageIndex: number, dpi?: number): number;
82
+ /**
83
+ * Render a page to fit inside a `width × height` pixel box, preserving
84
+ * aspect ratio. Picks the largest DPI such that both rendered
85
+ * dimensions are ≤ the target box, so the output may be smaller than
86
+ * `width × height` on one axis. Issue #448.
87
+ *
88
+ * @param pageIndex zero-based page index
89
+ * @param width target box width (pixels, must be > 0)
90
+ * @param height target box height (pixels, must be > 0)
91
+ * @param format `'png'` (default) or `'jpeg'`
92
+ */
93
+ renderPageFit(pageIndex: number, width: number, height: number, format?: 'png' | 'jpeg'): Uint8Array;
82
94
  page(index: number): Page;
83
95
  [Symbol.iterator](): Iterator<Page>;
96
+ /**
97
+ * Async iteration over the document's pages — issue #447. The body
98
+ * is identical to the sync iterator (page handles are constructed
99
+ * synchronously) but exposing this surface lets consumers `for await`
100
+ * uniformly with other async resources without an explicit
101
+ * `Promise.resolve(...)`.
102
+ */
103
+ [Symbol.asyncIterator](): AsyncIterator<Page>;
84
104
  /**
85
105
  * Validate PDF/A conformance at a given level.
86
106
  * @param level - "1a"|"1b"|"2a"|"2b"|"2u"|"3a"|"3b"|"3u" (default "2b")
package/lib/index.js CHANGED
@@ -313,6 +313,34 @@ class PdfDocumentImpl {
313
313
  this.ensureOpen();
314
314
  return native.estimateRenderTime(this._handle, pageIndex, dpi);
315
315
  }
316
+ /**
317
+ * Render a page to fit inside a `width × height` pixel box, preserving
318
+ * aspect ratio. Picks the largest DPI such that both rendered
319
+ * dimensions are ≤ the target box, so the output may be smaller than
320
+ * `width × height` on one axis. Issue #448.
321
+ *
322
+ * @param pageIndex zero-based page index
323
+ * @param width target box width (pixels, must be > 0)
324
+ * @param height target box height (pixels, must be > 0)
325
+ * @param format `'png'` (default) or `'jpeg'`
326
+ */
327
+ renderPageFit(pageIndex, width, height, format = 'png') {
328
+ this.ensureOpen();
329
+ if (width <= 0 || height <= 0) {
330
+ throw new RangeError(`width and height must be > 0, got ${width}×${height}`);
331
+ }
332
+ const fmt = format === 'jpeg' ? 1 : 0;
333
+ const imgHandle = native.renderPageFit(this._handle, pageIndex, width, height, fmt);
334
+ try {
335
+ const buf = native.pdfGetRenderedImageData(imgHandle);
336
+ return new Uint8Array(buf);
337
+ }
338
+ finally {
339
+ if (native.freeRenderedImage) {
340
+ native.freeRenderedImage(imgHandle);
341
+ }
342
+ }
343
+ }
316
344
  page(index) {
317
345
  this.ensureOpen();
318
346
  const count = this.pageCount();
@@ -334,6 +362,26 @@ class PdfDocumentImpl {
334
362
  },
335
363
  };
336
364
  }
365
+ /**
366
+ * Async iteration over the document's pages — issue #447. The body
367
+ * is identical to the sync iterator (page handles are constructed
368
+ * synchronously) but exposing this surface lets consumers `for await`
369
+ * uniformly with other async resources without an explicit
370
+ * `Promise.resolve(...)`.
371
+ */
372
+ [Symbol.asyncIterator]() {
373
+ this.ensureOpen();
374
+ const count = this.pageCount();
375
+ let i = 0;
376
+ const doc = this;
377
+ return {
378
+ async next() {
379
+ if (i >= count)
380
+ return { value: undefined, done: true };
381
+ return { value: new Page(doc, i++), done: false };
382
+ },
383
+ };
384
+ }
337
385
  /**
338
386
  * Validate PDF/A conformance at a given level.
339
387
  * @param level - "1a"|"1b"|"2a"|"2b"|"2u"|"3a"|"3b"|"3u" (default "2b")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-oxide",
3
- "version": "0.3.42",
3
+ "version": "0.3.43",
4
4
  "type": "module",
5
5
  "description": "High-performance PDF parsing and text extraction library — prebuilt native bindings, no build toolchain required",
6
6
  "main": "lib/index.js",
@@ -69,7 +69,7 @@
69
69
  "devDependencies": {
70
70
  "@types/node": "^18.0.0",
71
71
  "node-addon-api": "^8.7.0",
72
- "rimraf": "^5.0.0",
72
+ "rimraf": "^6.1.3",
73
73
  "typescript": "^5.3.0"
74
74
  },
75
75
  "gypfile": false
Binary file
Binary file
Binary file