@ironsoftware/ironpdf 2026.4.1 → 2026.6.1
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/package.json +3 -3
- package/src/index.d.ts +3 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +3 -0
- package/src/index.js.map +1 -1
- package/src/index.ts +3 -0
- package/src/internal/IronPdfEngine.ProtoFiles/chrome_render.proto +6 -0
- package/src/internal/IronPdfEngine.ProtoFiles/iron_pdf_service.proto +7 -1
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_compress.proto +1 -0
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_form.proto +32 -0
- package/src/internal/IronPdfEngine.ProtoFiles/qpdf.proto +51 -0
- package/src/internal/access.d.ts.map +1 -1
- package/src/internal/access.js +3 -0
- package/src/internal/access.js.map +1 -1
- package/src/internal/access.ts +4 -0
- package/src/internal/generated_proto/iron_pdf_service.d.ts +628 -305
- package/src/internal/generated_proto/iron_pdf_service.d.ts.map +1 -1
- package/src/internal/generated_proto/iron_pdf_service.ts +628 -305
- package/src/internal/generated_proto/ironpdfengineproto/ChromePdfRenderOptionsP.d.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/ChromePdfRenderOptionsP.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/ChromePdfRenderOptionsP.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts +52 -0
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.ts +64 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCompressImagesRequestP.d.ts +2 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCompressImagesRequestP.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCompressImagesRequestP.ts +2 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackRequestP.d.ts +8 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackRequestP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackRequestP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackRequestP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackRequestP.ts +11 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackResultP.d.ts +12 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackResultP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackResultP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackResultP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumDisableFormFontFallbackResultP.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontRequestStreamP.d.ts +25 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontRequestStreamP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontRequestStreamP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontRequestStreamP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontRequestStreamP.ts +28 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontResultP.d.ts +12 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontResultP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontResultP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontResultP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSetFormFontResultP.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedFromBytesRequestStreamP.d.ts +23 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedFromBytesRequestStreamP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedFromBytesRequestStreamP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedFromBytesRequestStreamP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedFromBytesRequestStreamP.ts +26 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedRequestP.d.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedRequestP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedRequestP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedRequestP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressAndSaveAsAdvancedRequestP.ts +18 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressionFlagsP.d.ts +30 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressionFlagsP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressionFlagsP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressionFlagsP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressionFlagsP.ts +33 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.d.ts +10 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.ts +13 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.d.ts +18 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.ts +21 -0
- package/src/internal/grpc_layer/chrome/converter.d.ts +10 -0
- package/src/internal/grpc_layer/chrome/converter.d.ts.map +1 -1
- package/src/internal/grpc_layer/chrome/converter.js +61 -2
- package/src/internal/grpc_layer/chrome/converter.js.map +1 -1
- package/src/internal/grpc_layer/chrome/converter.ts +67 -0
- package/src/internal/grpc_layer/pdfium/annotations.d.ts +30 -0
- package/src/internal/grpc_layer/pdfium/annotations.d.ts.map +1 -0
- package/src/internal/grpc_layer/pdfium/annotations.js +161 -0
- package/src/internal/grpc_layer/pdfium/annotations.js.map +1 -0
- package/src/internal/grpc_layer/pdfium/annotations.ts +190 -0
- package/src/internal/grpc_layer/pdfium/bookmarks.d.ts +7 -0
- package/src/internal/grpc_layer/pdfium/bookmarks.d.ts.map +1 -0
- package/src/internal/grpc_layer/pdfium/bookmarks.js +53 -0
- package/src/internal/grpc_layer/pdfium/bookmarks.js.map +1 -0
- package/src/internal/grpc_layer/pdfium/bookmarks.ts +50 -0
- package/src/internal/grpc_layer/pdfium/compress.d.ts +28 -0
- package/src/internal/grpc_layer/pdfium/compress.d.ts.map +1 -1
- package/src/internal/grpc_layer/pdfium/compress.js +154 -3
- package/src/internal/grpc_layer/pdfium/compress.js.map +1 -1
- package/src/internal/grpc_layer/pdfium/compress.ts +191 -1
- package/src/internal/grpc_layer/pdfium/form.d.ts +15 -0
- package/src/internal/grpc_layer/pdfium/form.d.ts.map +1 -0
- package/src/internal/grpc_layer/pdfium/form.js +99 -0
- package/src/internal/grpc_layer/pdfium/form.js.map +1 -0
- package/src/internal/grpc_layer/pdfium/form.ts +119 -0
- package/src/internal/grpc_layer/pdfium/formFontValidator.d.ts +26 -0
- package/src/internal/grpc_layer/pdfium/formFontValidator.d.ts.map +1 -0
- package/src/internal/grpc_layer/pdfium/formFontValidator.js +81 -0
- package/src/internal/grpc_layer/pdfium/formFontValidator.js.map +1 -0
- package/src/internal/grpc_layer/pdfium/formFontValidator.ts +86 -0
- package/src/internal/grpc_layer/pdfium/linearize.d.ts +48 -0
- package/src/internal/grpc_layer/pdfium/linearize.d.ts.map +1 -0
- package/src/internal/grpc_layer/pdfium/linearize.js +309 -0
- package/src/internal/grpc_layer/pdfium/linearize.js.map +1 -0
- package/src/internal/grpc_layer/pdfium/linearize.ts +338 -0
- package/src/internal/zod/renderSchema.d.ts.map +1 -1
- package/src/internal/zod/renderSchema.js +6 -1
- package/src/internal/zod/renderSchema.js.map +1 -1
- package/src/internal/zod/renderSchema.ts +6 -1
- package/src/public/annotation.d.ts +166 -0
- package/src/public/annotation.d.ts.map +1 -0
- package/src/public/annotation.js +61 -0
- package/src/public/annotation.js.map +1 -0
- package/src/public/annotation.ts +166 -0
- package/src/public/bookmark.d.ts +25 -0
- package/src/public/bookmark.d.ts.map +1 -0
- package/src/public/bookmark.js +3 -0
- package/src/public/bookmark.js.map +1 -0
- package/src/public/bookmark.ts +28 -0
- package/src/public/compression.d.ts +92 -0
- package/src/public/compression.d.ts.map +1 -0
- package/src/public/compression.js +26 -0
- package/src/public/compression.js.map +1 -0
- package/src/public/compression.ts +107 -0
- package/src/public/ironpdfglobalconfig.d.ts +12 -0
- package/src/public/ironpdfglobalconfig.d.ts.map +1 -1
- package/src/public/ironpdfglobalconfig.js +7 -0
- package/src/public/ironpdfglobalconfig.js.map +1 -1
- package/src/public/ironpdfglobalconfig.ts +19 -0
- package/src/public/pdfDocument.d.ts +234 -1
- package/src/public/pdfDocument.d.ts.map +1 -1
- package/src/public/pdfDocument.js +489 -17
- package/src/public/pdfDocument.js.map +1 -1
- package/src/public/pdfDocument.ts +518 -19
- package/src/public/render.d.ts +104 -0
- package/src/public/render.d.ts.map +1 -1
- package/src/public/render.js +35 -1
- package/src/public/render.js.map +1 -1
- package/src/public/render.ts +101 -0
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -33,6 +56,11 @@ const io_1 = require("../internal/grpc_layer/pdfium/io");
|
|
|
33
56
|
const access_1 = require("../internal/access");
|
|
34
57
|
const image_1 = require("../internal/grpc_layer/chrome/image");
|
|
35
58
|
const compress_1 = require("../internal/grpc_layer/pdfium/compress");
|
|
59
|
+
const form_1 = require("../internal/grpc_layer/pdfium/form");
|
|
60
|
+
const path = __importStar(require("path"));
|
|
61
|
+
const linearize_1 = require("../internal/grpc_layer/pdfium/linearize");
|
|
62
|
+
const annotations_1 = require("../internal/grpc_layer/pdfium/annotations");
|
|
63
|
+
const bookmarks_1 = require("../internal/grpc_layer/pdfium/bookmarks");
|
|
36
64
|
const page_1 = require("../internal/grpc_layer/pdfium/page");
|
|
37
65
|
const image_2 = require("../internal/grpc_layer/pdfium/image");
|
|
38
66
|
const jimp_1 = __importDefault(require("jimp"));
|
|
@@ -44,6 +72,7 @@ const headerFooter_1 = require("../internal/grpc_layer/pdfium/headerFooter");
|
|
|
44
72
|
const stamp_1 = require("../internal/grpc_layer/chrome/stamp");
|
|
45
73
|
const BackgroundForeground_1 = require("../internal/grpc_layer/pdfium/BackgroundForeground");
|
|
46
74
|
const security_1 = require("../internal/grpc_layer/pdfium/security");
|
|
75
|
+
const naturalLanguages_1 = require("./naturalLanguages");
|
|
47
76
|
/**
|
|
48
77
|
* Represents a PDF document. Allows: loading, editing, manipulating, merging, signing printing and saving PDFs.
|
|
49
78
|
*
|
|
@@ -285,6 +314,298 @@ class PdfDocument {
|
|
|
285
314
|
.implement(this.internal_compressAndSaveAs.bind(this))(filePath, imageQuality);
|
|
286
315
|
});
|
|
287
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Apply the advanced compression pipeline and save the result to a file.
|
|
319
|
+
*
|
|
320
|
+
* Combines pdfium-side image DPI downsampling with qpdf-side structural
|
|
321
|
+
* optimization in a single call.
|
|
322
|
+
*
|
|
323
|
+
* @param filePath the file path to save the compressed PDF
|
|
324
|
+
* @param options advanced compression options; pass an empty object `{}` to
|
|
325
|
+
* reproduce the legacy compressAndSaveAs behaviour with no
|
|
326
|
+
* image downsampling
|
|
327
|
+
* @param password the PDF password (empty string if none)
|
|
328
|
+
*/
|
|
329
|
+
compressAndSaveAsAdvanced(filePath, options, password) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
return this.internal_compressAndSaveAsAdvanced(filePath, options, password);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Apply the advanced compression pipeline to byte[] input and save the
|
|
336
|
+
* compressed result to a file. Returns the compressed bytes as well.
|
|
337
|
+
*/
|
|
338
|
+
static compressAndSaveAsAdvancedFromBytes(pdfBytes, filePath, options, password) {
|
|
339
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
340
|
+
if (!pdfBytes || pdfBytes.length === 0) {
|
|
341
|
+
throw new Error("pdfBytes must not be null or empty");
|
|
342
|
+
}
|
|
343
|
+
if (!options) {
|
|
344
|
+
throw new Error("options must not be null");
|
|
345
|
+
}
|
|
346
|
+
return (0, compress_1.compressAndSaveAsAdvancedFromBytes)(pdfBytes, filePath, options, password !== null && password !== void 0 ? password : "");
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region form (PDF-2184)
|
|
351
|
+
/**
|
|
352
|
+
* Set the document-wide form font for subsequent form-field fills. When
|
|
353
|
+
* set, the engine skips its automatic Tahoma/Arial fallback embed for
|
|
354
|
+
* non-ASCII form values and registers the supplied font in the AcroForm
|
|
355
|
+
* /DR /Font dictionary so default-appearance strings resolve correctly
|
|
356
|
+
* at render time.
|
|
357
|
+
*
|
|
358
|
+
* File-size impact:
|
|
359
|
+
* - Name-only mode (`fontData` omitted or empty): zero bytes added; the
|
|
360
|
+
* font must already be in the document.
|
|
361
|
+
* - Bytes mode and the font is already embedded with usable glyph data:
|
|
362
|
+
* zero bytes added.
|
|
363
|
+
* - Bytes mode and the font is missing or has no glyph data: the full
|
|
364
|
+
* font is embedded.
|
|
365
|
+
* - Bytes mode with `forceEmbed = true`: a fresh font copy is added
|
|
366
|
+
* alongside any existing copy; the document grows on every call.
|
|
367
|
+
*
|
|
368
|
+
* @param fontName PDF font name to register (e.g. "Poppins-Regular").
|
|
369
|
+
* Allowed characters: letters, digits, `_`, `-`, `.`, `+`.
|
|
370
|
+
* @param fontData Raw TrueType/OpenType bytes; pass `undefined` or an
|
|
371
|
+
* empty Buffer for name-only mode.
|
|
372
|
+
* @param forceEmbed When true, embed `fontData` even if a font with the
|
|
373
|
+
* same name and usable glyph data is already present.
|
|
374
|
+
*/
|
|
375
|
+
setFormFont(fontName, fontData, forceEmbed = false) {
|
|
376
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
377
|
+
return (0, form_1.setFormFont)(yield this.internal_getId(), fontName, fontData, forceEmbed);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Load a TrueType/OpenType font from disk and apply it as the
|
|
382
|
+
* document-wide form font. The PDF font name is derived from the file
|
|
383
|
+
* name (without extension) when `fontName` is omitted.
|
|
384
|
+
*
|
|
385
|
+
* @param fontFilePath Path to a TTF/OTF/TTC font file
|
|
386
|
+
* @param fontName Optional PDF font name. When omitted the file name
|
|
387
|
+
* (without extension) is used.
|
|
388
|
+
* @param forceEmbed When true, embed even if the font is already present.
|
|
389
|
+
*/
|
|
390
|
+
setFormFontFromFile(fontFilePath, fontName, forceEmbed = false) {
|
|
391
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
392
|
+
if (!fontFilePath) {
|
|
393
|
+
throw new Error("fontFilePath must not be empty");
|
|
394
|
+
}
|
|
395
|
+
const fontData = fs_1.default.readFileSync(fontFilePath);
|
|
396
|
+
const resolvedName = fontName !== null && fontName !== void 0 ? fontName : deriveFontNameFromPath(fontFilePath);
|
|
397
|
+
return (0, form_1.setFormFont)(yield this.internal_getId(), resolvedName, fontData, forceEmbed);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Suppress the automatic Tahoma/Arial fallback embed for non-ASCII form
|
|
402
|
+
* values without registering any replacement font. Use when zero
|
|
403
|
+
* file-size growth is required and the template's existing font
|
|
404
|
+
* references are sufficient for the values being filled.
|
|
405
|
+
*
|
|
406
|
+
* Rendering of non-ASCII characters then depends entirely on the
|
|
407
|
+
* viewer's font substitution.
|
|
408
|
+
*/
|
|
409
|
+
disableFormFontFallback() {
|
|
410
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
411
|
+
return (0, form_1.disableFormFontFallback)(yield this.internal_getId());
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region linearize
|
|
416
|
+
/**
|
|
417
|
+
* Linearize the current PDF document and return the result as a {@link Buffer} (byte array).
|
|
418
|
+
* Produces a web-optimized PDF that can be viewed incrementally in a browser.
|
|
419
|
+
*
|
|
420
|
+
* @param mode Linearization strategy. Defaults to {@link LinearizationMode.Automatic}.
|
|
421
|
+
* @returns A Promise resolving to a Buffer containing the linearized PDF bytes.
|
|
422
|
+
*/
|
|
423
|
+
linearizePdfToBytes(mode = types_1.LinearizationMode.Automatic) {
|
|
424
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
return this.internal_linearizePdfToBytes(mode);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Linearize the current PDF document and return the result as a {@link Readable} stream.
|
|
430
|
+
* Useful for piping directly to file streams or HTTP responses without buffering the
|
|
431
|
+
* entire PDF in memory.
|
|
432
|
+
*
|
|
433
|
+
* <b>Note:</b> Stream output is only supported with {@link LinearizationMode.InMemory}
|
|
434
|
+
* (or {@link LinearizationMode.Automatic} when memory mode is selected). For
|
|
435
|
+
* {@link LinearizationMode.FileBased} use {@link linearizePdfToBytes} or
|
|
436
|
+
* {@link saveAsLinearized}.
|
|
437
|
+
*
|
|
438
|
+
* @returns A Promise resolving to a Readable stream of the linearized PDF bytes.
|
|
439
|
+
*/
|
|
440
|
+
linearizePdfToStream() {
|
|
441
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
442
|
+
return this.internal_linearizePdfToStream();
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Linearize the current PDF document and save the result to the given output file path.
|
|
447
|
+
*
|
|
448
|
+
* @param outputFilePath The file path to save the linearized PDF.
|
|
449
|
+
* @param mode Linearization strategy. Defaults to {@link LinearizationMode.Automatic}.
|
|
450
|
+
*/
|
|
451
|
+
saveAsLinearized(outputFilePath, mode = types_1.LinearizationMode.Automatic) {
|
|
452
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
+
return yield zod_1.z.function()
|
|
454
|
+
.args(typeSchema_1.filePathSchema, zod_1.z.nativeEnum(types_1.LinearizationMode).optional())
|
|
455
|
+
.returns(zod_1.z.promise(zod_1.z.void()))
|
|
456
|
+
.implement((filePath, m) => __awaiter(this, void 0, void 0, function* () {
|
|
457
|
+
return this.internal_saveAsLinearized(filePath, m !== null && m !== void 0 ? m : types_1.LinearizationMode.Automatic);
|
|
458
|
+
}))(outputFilePath, mode);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Check whether the PDF file at the given path is linearized ("Fast Web View").
|
|
463
|
+
*
|
|
464
|
+
* @param pdfFilePath Path to a PDF file on disk.
|
|
465
|
+
* @param password Optional password for encrypted PDFs.
|
|
466
|
+
* @returns A Promise resolving to true if the file is linearized, false otherwise.
|
|
467
|
+
*/
|
|
468
|
+
static isLinearized(pdfFilePath, password = "") {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
470
|
+
return yield zod_1.z.function()
|
|
471
|
+
.args(typeSchema_1.pdfFilePathSchema, typeSchema_1.stringSchema.optional())
|
|
472
|
+
.returns(zod_1.z.promise(typeSchema_1.booleanSchema))
|
|
473
|
+
.implement((filePath, pwd) => __awaiter(this, void 0, void 0, function* () {
|
|
474
|
+
const bytes = fs_1.default.readFileSync(filePath);
|
|
475
|
+
return yield (0, linearize_1.isLinearizedFromBytes)(bytes, pwd !== null && pwd !== void 0 ? pwd : "");
|
|
476
|
+
}))(pdfFilePath, password);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Linearize the given PDF bytes and return the linearized bytes.
|
|
481
|
+
* Static helper for linearizing PDFs without creating a PdfDocument instance.
|
|
482
|
+
*
|
|
483
|
+
* @param pdfBytes Buffer containing the PDF data.
|
|
484
|
+
* @param password Optional password to decrypt the PDF if encrypted.
|
|
485
|
+
* @param mode Linearization strategy. Defaults to {@link LinearizationMode.Automatic}.
|
|
486
|
+
*/
|
|
487
|
+
static linearizePdfBytesToBytes(pdfBytes, password = "", mode = types_1.LinearizationMode.Automatic) {
|
|
488
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
+
return yield zod_1.z.function()
|
|
490
|
+
.args(typeSchema_1.bufferSchema, typeSchema_1.stringSchema.optional(), zod_1.z.nativeEnum(types_1.LinearizationMode).optional())
|
|
491
|
+
.returns(zod_1.z.promise(zod_1.z.instanceof(buffer_1.Buffer)))
|
|
492
|
+
.implement((bytes, pwd, m) => __awaiter(this, void 0, void 0, function* () {
|
|
493
|
+
return yield (0, linearize_1.linearizeCoreFromBytes)(bytes, pwd !== null && pwd !== void 0 ? pwd : "", m !== null && m !== void 0 ? m : types_1.LinearizationMode.Automatic);
|
|
494
|
+
}))(pdfBytes, password, mode);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Linearize the given PDF bytes and save the result to the given output file path.
|
|
499
|
+
* Static helper for linearizing PDFs without creating a PdfDocument instance.
|
|
500
|
+
*
|
|
501
|
+
* @param pdfBytes Buffer containing the PDF data.
|
|
502
|
+
* @param outputFilePath The file path to save the linearized PDF.
|
|
503
|
+
* @param password Optional password to decrypt the PDF if encrypted.
|
|
504
|
+
* @param mode Linearization strategy. Defaults to {@link LinearizationMode.Automatic}.
|
|
505
|
+
*/
|
|
506
|
+
static saveAsLinearizedFromBytes(pdfBytes, outputFilePath, password = "", mode = types_1.LinearizationMode.Automatic) {
|
|
507
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
+
return yield zod_1.z.function()
|
|
509
|
+
.args(typeSchema_1.bufferSchema, typeSchema_1.filePathSchema, typeSchema_1.stringSchema.optional(), zod_1.z.nativeEnum(types_1.LinearizationMode).optional())
|
|
510
|
+
.returns(zod_1.z.promise(zod_1.z.void()))
|
|
511
|
+
.implement((bytes, filePath, pwd, m) => __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
const linearized = yield (0, linearize_1.linearizeCoreFromBytes)(bytes, pwd !== null && pwd !== void 0 ? pwd : "", m !== null && m !== void 0 ? m : types_1.LinearizationMode.Automatic);
|
|
513
|
+
fs_1.default.writeFileSync(filePath, linearized);
|
|
514
|
+
}))(pdfBytes, outputFilePath, password, mode);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region elementLocations
|
|
519
|
+
/**
|
|
520
|
+
* Retrieves the rendered page locations of HTML elements that were tracked during rendering.
|
|
521
|
+
*
|
|
522
|
+
* To use this feature, set {@link ChromePdfRenderOptions.elementQuerySelectors} with CSS
|
|
523
|
+
* selectors before rendering. After rendering, call this method to retrieve the page index
|
|
524
|
+
* and coordinates of each matched element.
|
|
525
|
+
*
|
|
526
|
+
* Results are cached on first call and reused on subsequent calls. If you modify the
|
|
527
|
+
* document's annotations after rendering, call {@link resetElementLocationCache} to force
|
|
528
|
+
* the cache to be rebuilt on next access.
|
|
529
|
+
*
|
|
530
|
+
* Mirrors {@code IronPdf.PdfDocument.GetElementLocations()} on the C# side.
|
|
531
|
+
*
|
|
532
|
+
* @returns A list of {@link RenderedElementLocation} objects, one per matched element,
|
|
533
|
+
* sorted in document order. Returns an empty list if no element query selectors were
|
|
534
|
+
* configured or no elements matched.
|
|
535
|
+
*/
|
|
536
|
+
getElementLocations() {
|
|
537
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
538
|
+
return this.internal_getElementLocations();
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Clears the cached result of {@link getElementLocations}, forcing a fresh scan of the
|
|
543
|
+
* document's annotations on the next call. Call this if you've modified the document's
|
|
544
|
+
* annotations or structure after rendering.
|
|
545
|
+
*/
|
|
546
|
+
resetElementLocationCache() {
|
|
547
|
+
this.cachedElementLocations = null;
|
|
548
|
+
}
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region bookmarks
|
|
551
|
+
/**
|
|
552
|
+
* Retrieves all outline bookmarks (table-of-contents entries) in this PDF document.
|
|
553
|
+
*
|
|
554
|
+
* <p>Bookmarks are returned as a flat list with parent linkage via
|
|
555
|
+
* {@link Bookmark.parentItemId}. Roots have an empty {@code parentItemId}.
|
|
556
|
+
* Use {@link Bookmark.hierarchy} for depth information.</p>
|
|
557
|
+
*
|
|
558
|
+
* <p>Auto-bookmarks generated from HTML headings (via
|
|
559
|
+
* {@link ChromePdfRenderOptions.autoBookmarksFromHeadings}) are included.</p>
|
|
560
|
+
*
|
|
561
|
+
* <p>Mirrors {@code IronPdf.PdfDocument.Bookmarks} on the C# side.</p>
|
|
562
|
+
*
|
|
563
|
+
* @returns A list of {@link Bookmark} objects, sorted in document order.
|
|
564
|
+
* Returns an empty list if the document has no bookmarks.
|
|
565
|
+
*/
|
|
566
|
+
getBookmarks() {
|
|
567
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
568
|
+
return this.internal_getBookmarks();
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region annotation
|
|
573
|
+
/**
|
|
574
|
+
* Adds a clickable internal hyperlink annotation that navigates to another page within
|
|
575
|
+
* the same PDF document. Useful for building custom tables of contents, cross-references,
|
|
576
|
+
* and in-document navigation.
|
|
577
|
+
*
|
|
578
|
+
* The target page and display options are configured via the {@link LinkAnnotation}
|
|
579
|
+
* fields ({@code destinationPageIndex}, {@code destinationType}, etc.).
|
|
580
|
+
*
|
|
581
|
+
* Mirrors {@code IronPdf.Annotations.LinkAnnotation} on the C# side.
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```ts
|
|
585
|
+
* await pdf.addLinkAnnotation({
|
|
586
|
+
* pageIndex: 0,
|
|
587
|
+
* destinationPageIndex: 3,
|
|
588
|
+
* x: 72, y: 700,
|
|
589
|
+
* width: 300, height: 18,
|
|
590
|
+
* contents: "Chapter 1",
|
|
591
|
+
* });
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
addLinkAnnotation(link) {
|
|
595
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
596
|
+
return this.internal_addLinkAnnotation(link);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Retrieves the number of annotations contained on the specified page.
|
|
601
|
+
*
|
|
602
|
+
* @param pageIndex Zero-based page index. The first page has a page index of 0.
|
|
603
|
+
*/
|
|
604
|
+
getAnnotationCount(pageIndex) {
|
|
605
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
+
return this.internal_getAnnotationCount(pageIndex);
|
|
607
|
+
});
|
|
608
|
+
}
|
|
288
609
|
//#endregion
|
|
289
610
|
//#region page
|
|
290
611
|
/**
|
|
@@ -485,23 +806,20 @@ class PdfDocument {
|
|
|
485
806
|
.implement(this.internal_convertToPdfA.bind(this))(pdfaVersion, customICC);
|
|
486
807
|
});
|
|
487
808
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
// await toPdfUAForScreenReader(await pdf.internal_getId(), html, naturalLanguages);
|
|
503
|
-
// return pdf;
|
|
504
|
-
// }
|
|
809
|
+
/**
|
|
810
|
+
* Render HTML to PDF and convert to PDF/UA format with screen reader support.
|
|
811
|
+
* Produces a proper semantic structure tree (Sect → H1, P, etc.) for accessibility.
|
|
812
|
+
* @param html The HTML string to render
|
|
813
|
+
* @param naturalLanguages Document language for screen readers (default: English)
|
|
814
|
+
* @param options Optional render options
|
|
815
|
+
*/
|
|
816
|
+
static fromHtmlAsPdfUA(html, naturalLanguages = naturalLanguages_1.NaturalLanguages.English, options) {
|
|
817
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
818
|
+
const pdf = yield PdfDocument.fromHtml(html, options);
|
|
819
|
+
yield (0, pdfa_1.toPdfUAForScreenReader)(yield pdf.internal_getId(), html, naturalLanguages);
|
|
820
|
+
return pdf;
|
|
821
|
+
});
|
|
822
|
+
}
|
|
505
823
|
/**
|
|
506
824
|
* Convert the current document into the specified PDF/UA standard format
|
|
507
825
|
*/
|
|
@@ -852,6 +1170,15 @@ class PdfDocument {
|
|
|
852
1170
|
*/
|
|
853
1171
|
constructor(pdfInput, password, trackChanges) {
|
|
854
1172
|
var _a;
|
|
1173
|
+
/**
|
|
1174
|
+
* Cache for {@link getElementLocations}. Built lazily on first call.
|
|
1175
|
+
*
|
|
1176
|
+
* The underlying element-query anchor annotations are written during rendering and are
|
|
1177
|
+
* not expected to be mutated afterwards, so a simple populate-once cache is appropriate.
|
|
1178
|
+
* Callers who modify the document's annotations after rendering should call
|
|
1179
|
+
* {@link resetElementLocationCache} to force a rebuild.
|
|
1180
|
+
*/
|
|
1181
|
+
this.cachedElementLocations = null;
|
|
855
1182
|
if (pdfInput) {
|
|
856
1183
|
this.pdfDocumentId = undefined;
|
|
857
1184
|
const input = (0, util_1.separatePdfInput)(pdfInput);
|
|
@@ -1163,6 +1490,133 @@ class PdfDocument {
|
|
|
1163
1490
|
return yield (0, compress_1.compressAndSaveAs)(yield this.internal_getId(), filePath, imageQuality);
|
|
1164
1491
|
});
|
|
1165
1492
|
}
|
|
1493
|
+
internal_compressAndSaveAsAdvanced(filePath, options, password) {
|
|
1494
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1495
|
+
if (!filePath || filePath.trim().length === 0) {
|
|
1496
|
+
throw new Error("filePath must not be empty");
|
|
1497
|
+
}
|
|
1498
|
+
if (!options) {
|
|
1499
|
+
throw new Error("options must not be null");
|
|
1500
|
+
}
|
|
1501
|
+
if (options.jpegQuality !== undefined &&
|
|
1502
|
+
options.jpegQuality !== null &&
|
|
1503
|
+
(options.jpegQuality < 1 || options.jpegQuality > 100)) {
|
|
1504
|
+
throw new Error(`Invalid jpegQuality (${options.jpegQuality}). Must be between 1 and 100.`);
|
|
1505
|
+
}
|
|
1506
|
+
return yield (0, compress_1.compressAndSaveAsAdvanced)(yield this.internal_getId(), filePath, options, password !== null && password !== void 0 ? password : "");
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
//#endregion
|
|
1510
|
+
//#region linearize
|
|
1511
|
+
/**
|
|
1512
|
+
* Linearize the current PDF document and return the result as a Buffer.
|
|
1513
|
+
*/
|
|
1514
|
+
internal_linearizePdfToBytes(mode) {
|
|
1515
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1516
|
+
const id = yield this.internal_getId();
|
|
1517
|
+
return yield (0, linearize_1.linearizeCoreFromId)(id, () => this.internal_saveAsBuffer(), "", mode);
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Linearize the current PDF document and return the result as a Readable stream.
|
|
1522
|
+
* Always uses the in-memory streaming RPC.
|
|
1523
|
+
*/
|
|
1524
|
+
internal_linearizePdfToStream() {
|
|
1525
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1526
|
+
return yield (0, linearize_1.linearizeInMemoryFromIdStream)(yield this.internal_getId());
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Linearize the current PDF document and save the result to the given output file path.
|
|
1531
|
+
*/
|
|
1532
|
+
internal_saveAsLinearized(outputFilePath, mode) {
|
|
1533
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1534
|
+
const id = yield this.internal_getId();
|
|
1535
|
+
const linearized = yield (0, linearize_1.linearizeCoreFromId)(id, () => this.internal_saveAsBuffer(), "", mode);
|
|
1536
|
+
fs_1.default.writeFileSync(outputFilePath, linearized);
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
internal_getElementLocations() {
|
|
1540
|
+
var _a, _b, _c, _d, _e;
|
|
1541
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1542
|
+
if (this.cachedElementLocations !== null) {
|
|
1543
|
+
return this.cachedElementLocations;
|
|
1544
|
+
}
|
|
1545
|
+
const id = yield this.internal_getId();
|
|
1546
|
+
const pageInfos = yield (0, page_1.getPageInfo)(id);
|
|
1547
|
+
const locations = [];
|
|
1548
|
+
for (let pageIdx = 0; pageIdx < pageInfos.length; pageIdx++) {
|
|
1549
|
+
const annotations = yield (0, annotations_1.getAnnotations)(id, pageIdx);
|
|
1550
|
+
for (const wrapped of annotations) {
|
|
1551
|
+
if (!wrapped.link)
|
|
1552
|
+
continue;
|
|
1553
|
+
const dest = wrapped.link.dest;
|
|
1554
|
+
if (!dest || !dest.startsWith(PdfDocument.ELEMENT_QUERY_PREFIX))
|
|
1555
|
+
continue;
|
|
1556
|
+
const remainder = dest.substring(PdfDocument.ELEMENT_QUERY_PREFIX.length);
|
|
1557
|
+
const dashIdx = remainder.indexOf("-");
|
|
1558
|
+
if (dashIdx <= 0)
|
|
1559
|
+
continue;
|
|
1560
|
+
const indexStr = remainder.substring(0, dashIdx);
|
|
1561
|
+
const elementIndex = parseInt(indexStr, 10);
|
|
1562
|
+
if (isNaN(elementIndex))
|
|
1563
|
+
continue;
|
|
1564
|
+
const encodedText = remainder.substring(dashIdx + 1);
|
|
1565
|
+
let text;
|
|
1566
|
+
try {
|
|
1567
|
+
text = decodeURIComponent(encodedText);
|
|
1568
|
+
}
|
|
1569
|
+
catch (_f) {
|
|
1570
|
+
text = encodedText;
|
|
1571
|
+
}
|
|
1572
|
+
const innerRect = (_a = wrapped.link.annotation) === null || _a === void 0 ? void 0 : _a.rectangle;
|
|
1573
|
+
const rectangle = innerRect
|
|
1574
|
+
? {
|
|
1575
|
+
x: (_b = innerRect.x) !== null && _b !== void 0 ? _b : 0,
|
|
1576
|
+
y: (_c = innerRect.y) !== null && _c !== void 0 ? _c : 0,
|
|
1577
|
+
width: (_d = innerRect.width) !== null && _d !== void 0 ? _d : 0,
|
|
1578
|
+
height: (_e = innerRect.height) !== null && _e !== void 0 ? _e : 0,
|
|
1579
|
+
}
|
|
1580
|
+
: { x: 0, y: 0, width: 0, height: 0 };
|
|
1581
|
+
locations.push({ text, pageIndex: pageIdx, rectangle, elementIndex });
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
locations.sort((a, b) => a.elementIndex - b.elementIndex);
|
|
1585
|
+
this.cachedElementLocations = locations;
|
|
1586
|
+
return this.cachedElementLocations;
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
//#endregion
|
|
1590
|
+
//#region annotation
|
|
1591
|
+
internal_addLinkAnnotation(link) {
|
|
1592
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1593
|
+
if (!link) {
|
|
1594
|
+
throw new Error("link annotation cannot be null or undefined");
|
|
1595
|
+
}
|
|
1596
|
+
if (link.pageIndex < 0) {
|
|
1597
|
+
throw new Error("Invalid page index when adding link annotation");
|
|
1598
|
+
}
|
|
1599
|
+
if (link.destinationPageIndex < 0) {
|
|
1600
|
+
throw new Error("Invalid destination page index when adding link annotation");
|
|
1601
|
+
}
|
|
1602
|
+
yield (0, annotations_1.addLinkAnnotation)(yield this.internal_getId(), link);
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
internal_getAnnotationCount(pageIndex) {
|
|
1606
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1607
|
+
if (pageIndex < 0) {
|
|
1608
|
+
throw new Error("Invalid page index when getting annotation count");
|
|
1609
|
+
}
|
|
1610
|
+
return yield (0, annotations_1.getAnnotationCount)(yield this.internal_getId(), pageIndex);
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
//#endregion
|
|
1614
|
+
//#region bookmarks
|
|
1615
|
+
internal_getBookmarks() {
|
|
1616
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1617
|
+
return yield (0, bookmarks_1.getBookmarks)(yield this.internal_getId());
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1166
1620
|
//#endregion
|
|
1167
1621
|
//#region page
|
|
1168
1622
|
/**
|
|
@@ -1649,4 +2103,22 @@ class PdfDocument {
|
|
|
1649
2103
|
}
|
|
1650
2104
|
}
|
|
1651
2105
|
exports.PdfDocument = PdfDocument;
|
|
2106
|
+
//#endregion
|
|
2107
|
+
//#region elementLocations
|
|
2108
|
+
/**
|
|
2109
|
+
* Prefix used by the engine-side element query JavaScript extension when injecting anchor
|
|
2110
|
+
* markers. Must match {@code IronPdf.TableOfContents.ElementQueryJavascriptExtension.ELEMENT_QUERY_PREFIX}
|
|
2111
|
+
* on the C# side.
|
|
2112
|
+
*/
|
|
2113
|
+
PdfDocument.ELEMENT_QUERY_PREFIX = "ironpdf-elq-";
|
|
2114
|
+
/**
|
|
2115
|
+
* Derive a PDF font name from a font file path: strip the directory and the
|
|
2116
|
+
* extension. Used by {@link PdfDocument.setFormFontFromFile} when no
|
|
2117
|
+
* explicit name is supplied.
|
|
2118
|
+
*/
|
|
2119
|
+
function deriveFontNameFromPath(fontFilePath) {
|
|
2120
|
+
const base = path.basename(fontFilePath);
|
|
2121
|
+
const dot = base.lastIndexOf(".");
|
|
2122
|
+
return dot > 0 ? base.substring(0, dot) : base;
|
|
2123
|
+
}
|
|
1652
2124
|
//# sourceMappingURL=pdfDocument.js.map
|