pdf-oxide 0.3.40 → 0.3.42
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 +23 -1
- package/lib/index.js +74 -1
- package/lib/managers/barcode-manager.d.ts +3 -0
- package/lib/managers/barcode-manager.js +27 -0
- package/package.json +1 -1
- 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
|
@@ -81,6 +81,26 @@ declare class PdfDocumentImpl {
|
|
|
81
81
|
estimateRenderTime(pageIndex: number, dpi?: number): number;
|
|
82
82
|
page(index: number): Page;
|
|
83
83
|
[Symbol.iterator](): Iterator<Page>;
|
|
84
|
+
/**
|
|
85
|
+
* Validate PDF/A conformance at a given level.
|
|
86
|
+
* @param level - "1a"|"1b"|"2a"|"2b"|"2u"|"3a"|"3b"|"3u" (default "2b")
|
|
87
|
+
*/
|
|
88
|
+
validatePdfA(level?: '1a' | '1b' | '2a' | '2b' | '2u' | '3a' | '3b' | '3u'): {
|
|
89
|
+
compliant: boolean;
|
|
90
|
+
errors: string[];
|
|
91
|
+
warnings: string[];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Convert document to PDF/A conformance in-place.
|
|
95
|
+
* @param level - "1b"|"2b"|"2u"|"3b" etc. (default "2b")
|
|
96
|
+
* @returns true if the document is fully PDF/A-compliant after conversion (false if errors remain, e.g. fonts not embeddable without the rendering feature)
|
|
97
|
+
*/
|
|
98
|
+
convertToPdfA(level?: '1a' | '1b' | '2a' | '2b' | '2u' | '3a' | '3b' | '3u'): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Return the current document bytes (including any in-place modifications
|
|
101
|
+
* made by convertToPdfA).
|
|
102
|
+
*/
|
|
103
|
+
toBuffer(): Buffer;
|
|
84
104
|
close(): void;
|
|
85
105
|
[Symbol.dispose](): void;
|
|
86
106
|
}
|
|
@@ -107,6 +127,8 @@ declare class Page {
|
|
|
107
127
|
search(query: string, caseSensitive?: boolean): any;
|
|
108
128
|
toString(): string;
|
|
109
129
|
}
|
|
130
|
+
declare function generateBarcodeSvg(data: string, format?: number, sizePx?: number): string;
|
|
131
|
+
declare function generateQrCodeSvg(data: string, errorCorrection?: number, sizePx?: number): string;
|
|
110
132
|
declare const getVersion: any;
|
|
111
133
|
declare const getPdfOxideVersion: any;
|
|
112
134
|
declare const PdfDocument: any;
|
|
@@ -123,4 +145,4 @@ declare const TextSearcher: any;
|
|
|
123
145
|
export { Timestamp, TimestampHashAlgorithm } from './timestamp.js';
|
|
124
146
|
export { TsaClient, type TsaClientOptions } from './tsa-client.js';
|
|
125
147
|
export type { BatchDocument, BatchOptions, BatchProgress, BatchResult, BatchStatistics, Column, SpanCell, StreamingTableConfig, Table, TableMode, TableSpec, WorkerResult, WorkerTask, };
|
|
126
|
-
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, 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, };
|
|
148
|
+
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, };
|
package/lib/index.js
CHANGED
|
@@ -334,6 +334,57 @@ class PdfDocumentImpl {
|
|
|
334
334
|
},
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Validate PDF/A conformance at a given level.
|
|
339
|
+
* @param level - "1a"|"1b"|"2a"|"2b"|"2u"|"3a"|"3b"|"3u" (default "2b")
|
|
340
|
+
*/
|
|
341
|
+
validatePdfA(level = '2b') {
|
|
342
|
+
this.ensureOpen();
|
|
343
|
+
const levelMap = {
|
|
344
|
+
'1b': 0,
|
|
345
|
+
'1a': 1,
|
|
346
|
+
'2b': 2,
|
|
347
|
+
'2a': 3,
|
|
348
|
+
'2u': 4,
|
|
349
|
+
'3b': 5,
|
|
350
|
+
'3a': 6,
|
|
351
|
+
'3u': 7,
|
|
352
|
+
};
|
|
353
|
+
const levelInt = levelMap[level];
|
|
354
|
+
if (levelInt === undefined)
|
|
355
|
+
throw new RangeError(`Unknown PDF/A level: "${level}"`);
|
|
356
|
+
return native.validatePdfALevel(this._handle, levelInt);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Convert document to PDF/A conformance in-place.
|
|
360
|
+
* @param level - "1b"|"2b"|"2u"|"3b" etc. (default "2b")
|
|
361
|
+
* @returns true if the document is fully PDF/A-compliant after conversion (false if errors remain, e.g. fonts not embeddable without the rendering feature)
|
|
362
|
+
*/
|
|
363
|
+
convertToPdfA(level = '2b') {
|
|
364
|
+
this.ensureOpen();
|
|
365
|
+
const levelMap = {
|
|
366
|
+
'1b': 0,
|
|
367
|
+
'1a': 1,
|
|
368
|
+
'2b': 2,
|
|
369
|
+
'2a': 3,
|
|
370
|
+
'2u': 4,
|
|
371
|
+
'3b': 5,
|
|
372
|
+
'3a': 6,
|
|
373
|
+
'3u': 7,
|
|
374
|
+
};
|
|
375
|
+
const levelInt = levelMap[level];
|
|
376
|
+
if (levelInt === undefined)
|
|
377
|
+
throw new RangeError(`Unknown PDF/A level: "${level}"`);
|
|
378
|
+
return native.convertToPdfA(this._handle, levelInt);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Return the current document bytes (including any in-place modifications
|
|
382
|
+
* made by convertToPdfA).
|
|
383
|
+
*/
|
|
384
|
+
toBuffer() {
|
|
385
|
+
this.ensureOpen();
|
|
386
|
+
return native.documentGetSourceBytes(this._handle);
|
|
387
|
+
}
|
|
337
388
|
close() {
|
|
338
389
|
if (!this._closed && this._handle) {
|
|
339
390
|
native.closeDocument(this._handle);
|
|
@@ -465,6 +516,28 @@ class PdfImpl {
|
|
|
465
516
|
this.close();
|
|
466
517
|
}
|
|
467
518
|
}
|
|
519
|
+
// Generate a 1D barcode as a vector SVG string.
|
|
520
|
+
// format: 0=Code128, 1=Code39, 2=EAN13, 3=EAN8, 4=UPCA, 5=ITF, 6=Code93, 7=Codabar.
|
|
521
|
+
function generateBarcodeSvg(data, format = 0, sizePx = 300) {
|
|
522
|
+
const handle = native.generateBarcode(format, data);
|
|
523
|
+
try {
|
|
524
|
+
return native.barcodeGetSVG(handle, sizePx);
|
|
525
|
+
}
|
|
526
|
+
finally {
|
|
527
|
+
native.freeBarcode(handle);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// Generate a QR code as a vector SVG string.
|
|
531
|
+
// errorCorrection: 0=Low, 1=Medium, 2=Quartile, 3=High.
|
|
532
|
+
function generateQrCodeSvg(data, errorCorrection = 1, sizePx = 300) {
|
|
533
|
+
const handle = native.generateQRCode(data, errorCorrection);
|
|
534
|
+
try {
|
|
535
|
+
return native.barcodeGetSVG(handle, sizePx);
|
|
536
|
+
}
|
|
537
|
+
finally {
|
|
538
|
+
native.freeBarcode(handle);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
468
541
|
// Export as ES module
|
|
469
542
|
const getVersion = native.getVersion;
|
|
470
543
|
const getPdfOxideVersion = native.getPdfOxideVersion;
|
|
@@ -493,7 +566,7 @@ DocumentBuilder,
|
|
|
493
566
|
// Editor mutation API
|
|
494
567
|
DocumentEditor, EditingManager, EmbeddedFont, EncryptionException, EnterpriseManager,
|
|
495
568
|
// Error utilities
|
|
496
|
-
ErrorCategory, ErrorSeverity, ExtractionManager, ExtractionStream, FieldVisibility, FontProperties, FormFieldManager, FormFieldType, getPdfOxideVersion,
|
|
569
|
+
ErrorCategory, ErrorSeverity, ExtractionManager, ExtractionStream, FieldVisibility, FontProperties, FormFieldManager, FormFieldType, generateBarcodeSvg, generateQrCodeSvg, getPdfOxideVersion,
|
|
497
570
|
// Version info
|
|
498
571
|
getVersion, HybridMLManager, ImageFormat, ImageProperties, InvalidStateException, IoException, IssueSeverity, LayerManager, MetadataBuilder, MetadataManager, MetadataStream, mapFfiErrorCode, OCRDetectionMode, OCRLanguage, OCRManager, OcrException,
|
|
499
572
|
// Managers (Phase 4+, consolidated in Phase 9)
|
|
@@ -49,6 +49,7 @@ export interface BarcodeGenerationConfig {
|
|
|
49
49
|
format?: BarcodeFormat;
|
|
50
50
|
width?: number;
|
|
51
51
|
height?: number;
|
|
52
|
+
sizePx?: number;
|
|
52
53
|
errorCorrection?: BarcodeErrorCorrection;
|
|
53
54
|
margin?: number;
|
|
54
55
|
}
|
|
@@ -68,6 +69,8 @@ export declare class BarcodeManager extends EventEmitter {
|
|
|
68
69
|
generateQrCode(data: string, errorCorrection?: QrErrorCorrection, sizePx?: number): Promise<Buffer>;
|
|
69
70
|
barcodeToPng(barcodeData: Buffer, sizePx?: number): Promise<Buffer>;
|
|
70
71
|
barcodeToSvg(barcodeData: Buffer, sizePx?: number): Promise<string>;
|
|
72
|
+
generateSvg(data: string, config?: BarcodeGenerationConfig): Promise<string>;
|
|
73
|
+
generateQrSvg(data: string, errorCorrection?: QrErrorCorrection, sizePx?: number): Promise<string>;
|
|
71
74
|
addBarcodeToPage(pageIndex: number, barcodeData: Buffer, x: number, y: number, width: number, height: number): Promise<boolean>;
|
|
72
75
|
detectBarcodeFormat(barcodeData: Buffer): BarcodeFormat;
|
|
73
76
|
decodeBarcodeData(barcodeData: Buffer): string;
|
|
@@ -187,9 +187,36 @@ export class BarcodeManager extends EventEmitter {
|
|
|
187
187
|
return barcodeData;
|
|
188
188
|
}
|
|
189
189
|
async barcodeToSvg(barcodeData, sizePx = 256) {
|
|
190
|
+
// Legacy: wraps existing PNG bytes in an SVG <image> element.
|
|
191
|
+
// For real vector SVG use generateBarcodeSvg() / generateQrCodeSvg() from the top-level API.
|
|
190
192
|
const encoded = barcodeData.toString('base64');
|
|
191
193
|
return `<svg xmlns="http://www.w3.org/2000/svg"><image href="data:image/png;base64,${encoded}"/></svg>`;
|
|
192
194
|
}
|
|
195
|
+
async generateSvg(data, config) {
|
|
196
|
+
const format = config?.format ?? BarcodeFormat.CODE128;
|
|
197
|
+
if (this.native?.generateBarcode && this.native?.barcodeGetSVG && this.native?.freeBarcode) {
|
|
198
|
+
const handle = this.native.generateBarcode(format, data);
|
|
199
|
+
try {
|
|
200
|
+
return this.native.barcodeGetSVG(handle, config?.sizePx ?? 300);
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
this.native.freeBarcode(handle);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return '';
|
|
207
|
+
}
|
|
208
|
+
async generateQrSvg(data, errorCorrection = QrErrorCorrection.M, sizePx = 300) {
|
|
209
|
+
if (this.native?.generateQRCode && this.native?.barcodeGetSVG && this.native?.freeBarcode) {
|
|
210
|
+
const handle = this.native.generateQRCode(data, errorCorrection);
|
|
211
|
+
try {
|
|
212
|
+
return this.native.barcodeGetSVG(handle, sizePx);
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
this.native.freeBarcode(handle);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return '';
|
|
219
|
+
}
|
|
193
220
|
async addBarcodeToPage(pageIndex, barcodeData, x, y, width, height) {
|
|
194
221
|
try {
|
|
195
222
|
if (!this.document)
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|