pdf-oxide 0.3.45 → 0.3.47
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 +38 -1
- package/lib/index.js +57 -3
- package/package.json +5 -2
- package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
- package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
- package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
- package/prebuilds/linux-x64/pdf_oxide.node +0 -0
- package/prebuilds/win32-x64/pdf_oxide.node +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -26,9 +26,21 @@ export interface RenderOptions {
|
|
|
26
26
|
/** JPEG quality 1..=100 (default 85). */
|
|
27
27
|
jpegQuality?: number;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Raw premultiplied RGBA8888 pixel buffer. Layout: row-major, top-left origin,
|
|
31
|
+
* 4 bytes (R,G,B,A) per pixel, `data.length === width * height * 4`.
|
|
32
|
+
* Alpha is premultiplied (PDF spec §11 transparency model).
|
|
33
|
+
*/
|
|
34
|
+
export interface RgbaPixmap {
|
|
35
|
+
data: Buffer;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
}
|
|
29
39
|
declare class PdfDocumentImpl {
|
|
30
40
|
private _handle;
|
|
31
41
|
private _closed;
|
|
42
|
+
/** Promise-cached mutex; single Promise ensures no race on concurrent first calls. */
|
|
43
|
+
private _muPromise;
|
|
32
44
|
constructor(handle: any);
|
|
33
45
|
static open(path: string): PdfDocumentImpl;
|
|
34
46
|
static openFromBuffer(buffer: Buffer | Uint8Array): PdfDocumentImpl;
|
|
@@ -91,6 +103,28 @@ declare class PdfDocumentImpl {
|
|
|
91
103
|
* @param format `'png'` (default) or `'jpeg'`
|
|
92
104
|
*/
|
|
93
105
|
renderPageFit(pageIndex: number, width: number, height: number, format?: 'png' | 'jpeg'): Uint8Array;
|
|
106
|
+
/** Lazy-initialises the per-instance Mutex (avoids a hard dep at load time). */
|
|
107
|
+
private _getMutex;
|
|
108
|
+
/**
|
|
109
|
+
* Async variant of {@link renderPageWithOptions} serialised through a
|
|
110
|
+
* per-instance mutex. Use when calling from `worker_threads` or `Promise.all`.
|
|
111
|
+
*/
|
|
112
|
+
renderPageWithOptionsAsync(pageIndex: number, options?: RenderOptions): Promise<Uint8Array>;
|
|
113
|
+
/**
|
|
114
|
+
* Async variant of {@link renderPageFit} serialised through a per-instance mutex.
|
|
115
|
+
*/
|
|
116
|
+
renderPageFitAsync(pageIndex: number, width: number, height: number, format?: 'png' | 'jpeg'): Promise<Uint8Array>;
|
|
117
|
+
/**
|
|
118
|
+
* Renders a page as raw premultiplied RGBA8888 pixels. No PNG/JPEG encoding
|
|
119
|
+
* overhead — useful for direct handoff to image-processing libraries.
|
|
120
|
+
* @param pageIndex Zero-based page index.
|
|
121
|
+
* @param dpi Resolution in dots per inch (default 150).
|
|
122
|
+
*/
|
|
123
|
+
renderToPixmap(pageIndex: number, dpi?: number): RgbaPixmap;
|
|
124
|
+
/**
|
|
125
|
+
* Async variant of {@link renderToPixmap} serialised through a per-instance mutex.
|
|
126
|
+
*/
|
|
127
|
+
renderToPixmapAsync(pageIndex: number, dpi?: number): Promise<RgbaPixmap>;
|
|
94
128
|
page(index: number): Page;
|
|
95
129
|
[Symbol.iterator](): Iterator<Page>;
|
|
96
130
|
/**
|
|
@@ -151,6 +185,9 @@ declare function generateBarcodeSvg(data: string, format?: number, sizePx?: numb
|
|
|
151
185
|
declare function generateQrCodeSvg(data: string, errorCorrection?: number, sizePx?: number): string;
|
|
152
186
|
declare const getVersion: any;
|
|
153
187
|
declare const getPdfOxideVersion: any;
|
|
188
|
+
declare const getActiveCryptoProvider: any;
|
|
189
|
+
declare const isFipsCryptoAvailable: any;
|
|
190
|
+
declare const useFipsCryptoProvider: any;
|
|
154
191
|
declare const PdfDocument: any;
|
|
155
192
|
declare const Pdf: any;
|
|
156
193
|
declare const PdfError: typeof PdfException;
|
|
@@ -165,4 +202,4 @@ declare const TextSearcher: any;
|
|
|
165
202
|
export { Timestamp, TimestampHashAlgorithm } from './timestamp.js';
|
|
166
203
|
export { TsaClient, type TsaClientOptions } from './tsa-client.js';
|
|
167
204
|
export type { BatchDocument, BatchOptions, BatchProgress, BatchResult, BatchStatistics, Column, SpanCell, StreamingTableConfig, Table, TableMode, TableSpec, WorkerResult, WorkerTask, };
|
|
168
|
-
export { AccessibilityException, AccessibilityManager, Align, AnnotationBuilder, AnnotationManager, AnnotationProperties, BarcodeErrorCorrection, BarcodeFormat, BarcodeManager, BatchManager, CacheManager, CertificateLoadFailed, Color, ComplianceException, ComplianceIssueType, ComplianceManager, ContentType, ConversionOptions, ConversionOptionsBuilder, createExtractionStream, createMetadataStream, createSearchStream, DigestAlgorithm, DocumentBuilder, DocumentEditor, EditingManager, EmbeddedFont, EncryptionException, EnterpriseManager, ErrorCategory, ErrorSeverity, ExtractionManager, ExtractionStream, FieldVisibility, FontProperties, FormFieldManager, FormFieldType, generateBarcodeSvg, generateQrCodeSvg, getPdfOxideVersion, getVersion, HybridMLManager, ImageFormat, ImageProperties, InvalidStateException, IoException, IssueSeverity, LayerManager, MetadataBuilder, MetadataManager, MetadataStream, mapFfiErrorCode, OCRDetectionMode, OCRLanguage, OCRManager, OcrException, OcrManager, OptimizationException, OptimizationManager, OutlineManager, Page, PageBuilder, PageComplexity, PageSize, ParseException, Pdf, PdfALevel, PdfBuilder, PdfDocument, PdfError, PdfException, PdfUALevel, PdfXLevel, Point, Rect, RedactionException, RenderingException, RenderingManager, ResultAccessorsManager, SearchException, SearchManager, SearchOptions, SearchOptionsBuilder, SearchResult, SearchResultProperties, SearchStream, SecurityManager, SignatureAlgorithm, SignatureException, SignatureManager, SigningFailed, StreamingTable, TextSearcher, ThumbnailManager, ThumbnailSize, UnknownError, UnsupportedFeatureException, ValidationException, WorkerPool, workerPool, wrapAsyncMethod, wrapError, wrapMethod, XfaFieldType, XfaFormType, XfaManager, };
|
|
205
|
+
export { AccessibilityException, AccessibilityManager, Align, AnnotationBuilder, AnnotationManager, AnnotationProperties, BarcodeErrorCorrection, BarcodeFormat, BarcodeManager, BatchManager, CacheManager, CertificateLoadFailed, Color, ComplianceException, ComplianceIssueType, ComplianceManager, ContentType, ConversionOptions, ConversionOptionsBuilder, createExtractionStream, createMetadataStream, createSearchStream, DigestAlgorithm, DocumentBuilder, DocumentEditor, EditingManager, EmbeddedFont, EncryptionException, EnterpriseManager, ErrorCategory, ErrorSeverity, ExtractionManager, ExtractionStream, FieldVisibility, FontProperties, FormFieldManager, FormFieldType, generateBarcodeSvg, generateQrCodeSvg, getActiveCryptoProvider, getPdfOxideVersion, getVersion, HybridMLManager, ImageFormat, ImageProperties, InvalidStateException, IoException, IssueSeverity, isFipsCryptoAvailable, LayerManager, MetadataBuilder, MetadataManager, MetadataStream, mapFfiErrorCode, OCRDetectionMode, OCRLanguage, OCRManager, OcrException, OcrManager, OptimizationException, OptimizationManager, OutlineManager, Page, PageBuilder, PageComplexity, PageSize, ParseException, Pdf, PdfALevel, PdfBuilder, PdfDocument, PdfError, PdfException, PdfUALevel, PdfXLevel, Point, Rect, RedactionException, RenderingException, RenderingManager, ResultAccessorsManager, SearchException, SearchManager, SearchOptions, SearchOptionsBuilder, SearchResult, SearchResultProperties, SearchStream, SecurityManager, SignatureAlgorithm, SignatureException, SignatureManager, SigningFailed, StreamingTable, TextSearcher, ThumbnailManager, ThumbnailSize, UnknownError, UnsupportedFeatureException, useFipsCryptoProvider, ValidationException, WorkerPool, workerPool, wrapAsyncMethod, wrapError, wrapMethod, XfaFieldType, XfaFormType, XfaManager, };
|
package/lib/index.js
CHANGED
|
@@ -138,6 +138,8 @@ function wrapNativeClass(nativeClass, asyncMethods = []) {
|
|
|
138
138
|
class PdfDocumentImpl {
|
|
139
139
|
constructor(handle) {
|
|
140
140
|
this._closed = false;
|
|
141
|
+
/** Promise-cached mutex; single Promise ensures no race on concurrent first calls. */
|
|
142
|
+
this._muPromise = null;
|
|
141
143
|
if (!handle)
|
|
142
144
|
throw new Error('Failed to open document');
|
|
143
145
|
this._handle = handle;
|
|
@@ -341,6 +343,55 @@ class PdfDocumentImpl {
|
|
|
341
343
|
}
|
|
342
344
|
}
|
|
343
345
|
}
|
|
346
|
+
/** Lazy-initialises the per-instance Mutex (avoids a hard dep at load time). */
|
|
347
|
+
_getMutex() {
|
|
348
|
+
if (!this._muPromise) {
|
|
349
|
+
this._muPromise = import('async-mutex').then(({ Mutex }) => new Mutex());
|
|
350
|
+
}
|
|
351
|
+
return this._muPromise;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Async variant of {@link renderPageWithOptions} serialised through a
|
|
355
|
+
* per-instance mutex. Use when calling from `worker_threads` or `Promise.all`.
|
|
356
|
+
*/
|
|
357
|
+
async renderPageWithOptionsAsync(pageIndex, options = {}) {
|
|
358
|
+
const mu = await this._getMutex();
|
|
359
|
+
return mu.runExclusive(() => this.renderPageWithOptions(pageIndex, options));
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Async variant of {@link renderPageFit} serialised through a per-instance mutex.
|
|
363
|
+
*/
|
|
364
|
+
async renderPageFitAsync(pageIndex, width, height, format = 'png') {
|
|
365
|
+
const mu = await this._getMutex();
|
|
366
|
+
return mu.runExclusive(() => this.renderPageFit(pageIndex, width, height, format));
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Renders a page as raw premultiplied RGBA8888 pixels. No PNG/JPEG encoding
|
|
370
|
+
* overhead — useful for direct handoff to image-processing libraries.
|
|
371
|
+
* @param pageIndex Zero-based page index.
|
|
372
|
+
* @param dpi Resolution in dots per inch (default 150).
|
|
373
|
+
*/
|
|
374
|
+
renderToPixmap(pageIndex, dpi = 150) {
|
|
375
|
+
this.ensureOpen();
|
|
376
|
+
if (dpi <= 0)
|
|
377
|
+
throw new RangeError(`dpi must be > 0, got ${dpi}`);
|
|
378
|
+
const { imgHandle, width, height } = native.renderPageRaw(this._handle, pageIndex, dpi);
|
|
379
|
+
try {
|
|
380
|
+
const buf = native.pdfGetRenderedImageData(imgHandle);
|
|
381
|
+
return { data: Buffer.from(buf), width, height };
|
|
382
|
+
}
|
|
383
|
+
finally {
|
|
384
|
+
if (native.freeRenderedImage)
|
|
385
|
+
native.freeRenderedImage(imgHandle);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Async variant of {@link renderToPixmap} serialised through a per-instance mutex.
|
|
390
|
+
*/
|
|
391
|
+
async renderToPixmapAsync(pageIndex, dpi = 150) {
|
|
392
|
+
const mu = await this._getMutex();
|
|
393
|
+
return mu.runExclusive(() => this.renderToPixmap(pageIndex, dpi));
|
|
394
|
+
}
|
|
344
395
|
page(index) {
|
|
345
396
|
this.ensureOpen();
|
|
346
397
|
const count = this.pageCount();
|
|
@@ -589,6 +640,9 @@ function generateQrCodeSvg(data, errorCorrection = 1, sizePx = 300) {
|
|
|
589
640
|
// Export as ES module
|
|
590
641
|
const getVersion = native.getVersion;
|
|
591
642
|
const getPdfOxideVersion = native.getPdfOxideVersion;
|
|
643
|
+
const getActiveCryptoProvider = native.getActiveCryptoProvider;
|
|
644
|
+
const isFipsCryptoAvailable = native.isFipsCryptoAvailable;
|
|
645
|
+
const useFipsCryptoProvider = native.useFipsCryptoProvider;
|
|
592
646
|
const PdfDocument = PdfDocumentImpl;
|
|
593
647
|
const Pdf = PdfImpl;
|
|
594
648
|
const PdfError = PdfException;
|
|
@@ -614,9 +668,9 @@ DocumentBuilder,
|
|
|
614
668
|
// Editor mutation API
|
|
615
669
|
DocumentEditor, EditingManager, EmbeddedFont, EncryptionException, EnterpriseManager,
|
|
616
670
|
// Error utilities
|
|
617
|
-
ErrorCategory, ErrorSeverity, ExtractionManager, ExtractionStream, FieldVisibility, FontProperties, FormFieldManager, FormFieldType, generateBarcodeSvg, generateQrCodeSvg, getPdfOxideVersion,
|
|
671
|
+
ErrorCategory, ErrorSeverity, ExtractionManager, ExtractionStream, FieldVisibility, FontProperties, FormFieldManager, FormFieldType, generateBarcodeSvg, generateQrCodeSvg, getActiveCryptoProvider, getPdfOxideVersion,
|
|
618
672
|
// Version info
|
|
619
|
-
getVersion, HybridMLManager, ImageFormat, ImageProperties, InvalidStateException, IoException, IssueSeverity, LayerManager, MetadataBuilder, MetadataManager, MetadataStream, mapFfiErrorCode, OCRDetectionMode, OCRLanguage, OCRManager, OcrException,
|
|
673
|
+
getVersion, HybridMLManager, ImageFormat, ImageProperties, InvalidStateException, IoException, IssueSeverity, isFipsCryptoAvailable, LayerManager, MetadataBuilder, MetadataManager, MetadataStream, mapFfiErrorCode, OCRDetectionMode, OCRLanguage, OCRManager, OcrException,
|
|
620
674
|
// Managers (Phase 4+, consolidated in Phase 9)
|
|
621
675
|
OcrManager, OptimizationException, OptimizationManager,
|
|
622
676
|
// Managers (Phase 1-3: Core)
|
|
@@ -634,6 +688,6 @@ SearchStream, SecurityManager, SignatureAlgorithm, SignatureException, Signature
|
|
|
634
688
|
// v0.3.39 — managed streaming-table adapter (#393)
|
|
635
689
|
StreamingTable,
|
|
636
690
|
// Utilities
|
|
637
|
-
TextSearcher, ThumbnailManager, ThumbnailSize, UnknownError, UnsupportedFeatureException, ValidationException,
|
|
691
|
+
TextSearcher, ThumbnailManager, ThumbnailSize, UnknownError, UnsupportedFeatureException, useFipsCryptoProvider, ValidationException,
|
|
638
692
|
// Worker Threads API
|
|
639
693
|
WorkerPool, workerPool, wrapAsyncMethod, wrapError, wrapMethod, XfaFieldType, XfaFormType, XfaManager, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-oxide",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.47",
|
|
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",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"check:publint": "publint",
|
|
21
21
|
"check:types": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
22
22
|
"audit:prod": "npm audit --omit=dev --audit-level=high",
|
|
23
|
-
"test": "node --test tests/smoke.test.mjs tests/feature-guard.test.mjs tests/api-coverage.test.mjs tests/html-css.test.mjs tests/document-builder.test.mjs tests/document-editor.test.mjs tests/render-options.test.mjs tests/tables.test.mjs"
|
|
23
|
+
"test": "node --test tests/smoke.test.mjs tests/feature-guard.test.mjs tests/api-coverage.test.mjs tests/html-css.test.mjs tests/document-builder.test.mjs tests/document-editor.test.mjs tests/render-options.test.mjs tests/tables.test.mjs tests/worker-threads-safety.test.mjs"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"lib/",
|
|
@@ -66,6 +66,9 @@
|
|
|
66
66
|
"import": "./lib/errors.js"
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"async-mutex": "^0.5.0"
|
|
71
|
+
},
|
|
69
72
|
"devDependencies": {
|
|
70
73
|
"@types/node": "^25.6.0",
|
|
71
74
|
"node-addon-api": "^8.7.0",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|