@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
2,833 lines • 107 kB
TypeScript
import { _PdfStream } from './base-stream';
import { _PdfCrossReference } from './pdf-cross-reference';
import { _Linearization } from './pdf-parser';
import { _PdfCatalog } from './pdf-catalog';
import { _PdfDictionary, _PdfReference } from './pdf-primitives';
import { PdfPage } from './pdf-page';
import { DataFormat, PdfPermissionFlag, PdfPageOrientation, PdfRotationAngle, PdfTemplateHorizontalAlignment, PdfTemplateVerticalAlignment, PdfTemplateLayerMode, _TemplateSide, _PdfAlignmentStyle } from './enumerator';
import { PdfForm } from './form/form';
import { _FontData, _PdfFontPrimitive, PdfCjkFontFamily, PdfCjkStandardFont, PdfFont, PdfFontFamily, PdfFontStyle, PdfStandardFont, PdfTrueTypeFont } from './fonts/pdf-standard-font';
import { PdfBookmarkBase, _PdfNamedDestinationCollection } from './pdf-outline';
import { PdfFileStructure } from './pdf-file-structure';
import { _PdfMergeHelper } from './pdf-merge';
import { PdfPageImportOptions } from './pdf-page-import-options';
import { PdfLayerCollection } from './layers/layer-collection';
import { PdfSection } from './pdf-section';
import { PdfDocumentInformation } from './pdf-document-information';
import { PdfSignature } from './security/digital-signature/signature/pdf-signature';
import { Rectangle, Size, PdfDocumentTemplate } from './pdf-type';
import { PdfXmpMetadata } from './xmp/pdf-xmp-metadata';
import { PdfPageTemplateElement } from './graphics/pdf-page-template-element';
/**
* Represents a PDF document and can be used to parse an existing PDF document.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Flatten annotations and form fields
* document.flatten = true;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfDocument {
/**
* Underlying input/output byte stream of the document.
*
* @private
*/
_stream: _PdfStream;
/**
* Cross reference table handler for resolving, writing, and caching indirect objects.
*
* @private
*/
_crossReference: _PdfCrossReference;
/**
* Catalog helper that exposes document level dictionaries like Pages, Outlines, etc.
*
* @private
*/
_catalog: _PdfCatalog;
/**
* Internal structure options and cross reference writing settings.
*
* @private
*/
_fileStructure: PdfFileStructure;
private _headerSignature;
private _startXrefSignature;
private _endObjSignature;
private _version;
/**
* Cache of instantiated `PdfPage` objects keyed by page index.
*
* @private
*/
_pages: Map<number, PdfPage>;
private _linear;
/**
* Cached document page count.
*
* @private
*/
_pageCount: number;
private _flatten;
/**
* Effective permission flags for the current document.
*
* @private
*/
_permissions: PdfPermissionFlag;
/**
* Form object wrapper for interacting with AcroForm fields.
*
* @private
*/
_form: PdfForm;
/**
* Root bookmark outline of the document.
*
* @private
*/
_bookmarkBase: PdfBookmarkBase;
/**
* Named destinations collection helper.
*
* @private
*/
_namedDestinationCollection: _PdfNamedDestinationCollection;
/**
* Indicates whether the source document is encrypted.
*
* @private
*/
_isEncrypted: boolean;
/**
* Indicates whether a user password was used to decrypt the document.
*
* @private
*/
_isUserPassword: boolean;
/**
* Indicates whether only a user password is present for the document.
*
* @private
*/
_hasUserPasswordOnly: boolean;
/**
* Indicates whether only attachments should be encrypted.
*
* @private
*/
_encryptOnlyAttachment: boolean;
/**
* Indicates whether metadata needs to be encrypted.
*
* @private
*/
_encryptMetaData: boolean;
/**
* Indicates whether the current operation is an export action (annotations/forms).
*
* @private
*/
_isExport: boolean;
private _allowCustomData;
/**
* Lookup table mapping pages to associated bookmark nodes for quick updates.
*
* @private
*/
_bookmarkHashTable: Map<PdfPage, PdfBookmarkBase[]>;
/**
* Target insertion index used during import/merge operations.
*
* @private
*/
_targetIndex: number;
/**
* Indicates that the current import operation is duplicating an existing page.
*
* @private
*/
_isDuplicatePage: boolean;
/**
* Cache of merge helpers keyed by source document unique id.
*
* @private
*/
_mergeHelperCache: Map<string, _PdfMergeHelper>;
/**
* Indicates that the current document is used during a split operation.
*
* @private
*/
_uniqueID: string;
/**
* Indicates that the current document is used during a split operation.
*
* @private
*/
_isSplitDocument: boolean;
private _layers;
/**
* Optional content configuration dictionary references.
*
* @private
*/
_optionalContentDictionaries: _PdfReference[];
/**
* Optional content order array of OCG/OCMD references.
*
* @private
*/
_order: (_PdfReference | _PdfReference[])[];
/**
* Optional content groups to be set ON.
*
* @private
*/
_on: _PdfReference[];
/**
* Optional content groups to be set OFF.
*
* @private
*/
_off: _PdfReference[];
/**
* Optional content group/intent relationships.
*
* @private
*/
_as: _PdfReference[];
/**
* Optional content groups to be printed.
*
* @private
*/
_printLayer: _PdfReference[];
/**
* Indicates whether the document was loaded from an existing byte source.
*
* @private
*/
_isLoaded: boolean;
/**
* Cache of created font primitives keyed by computed hash or descriptor.
*
* @private
*/
_fontCollection: Map<string, _PdfFontPrimitive>;
/**
* Parsed positions of "startxref" markers encountered during reading.
*
* @private
*/
_startXRefParsedCache: number[];
private _revisions;
_isFormImport: boolean;
private _xmpMetadata;
/**
* Stores the template configuration for document or section-level headers and footers.
*
* @private
*/
private _template;
/**
* Collection of sections within the document.
*
* @private
*/
_sections: PdfSection[];
/**
* Maintains background layer mappings for each page.
*
* @private
*/
private _backgroundLayers;
/**
* Indicates whether template rendering has started for the document.
*
* @private
*/
_templateRenderingStarted: boolean;
splitEvent: Function;
/**
* Creates a new PDF document
*
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new page
* let page: PdfPage = document.addPage();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a new pen.
* let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
* // Draw line on the page graphics.
* graphics.drawLine(pen, {x: 10, y: 10}, {x: 100, y: 100});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor();
/**
* Initializes a new instance of the `PdfDocument` class.
*
* @param {string} data PDF data as Base64 string.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Flatten annotations and form fields
* document.flatten = true;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(data: string);
/**
* Initializes a new instance of the `PdfDocument` class with password.
*
* @param {string} data PDF data as Base64 string.
* @param {string} password Password to decrypt PDF.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Flatten annotations and form fields
* document.flatten = true;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(data: string, password: string);
/**
* Initializes a new instance of the `PdfDocument` class.
*
* @param {Uint8Array} data PDF data as byte array.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Flatten annotations and form fields
* document.flatten = true;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(data: Uint8Array);
/**
* Initializes a new instance of the `PdfDocument` class with password.
*
* @param {Uint8Array} data PDF data as byte array.
* @param {string} password Password to decrypt PDF.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Flatten annotations and form fields
* document.flatten = true;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(data: Uint8Array, password: string);
/**
* Gets whether custom data import is allowed.
*
* @private
* @returns {boolean} `true` if importing custom data is allowed; otherwise, `false`.
*/
/**
* Sets whether custom data import is allowed.
*
* @private
* @param {boolean} value `true` to allow custom data import; otherwise, `false`.
*/
_allowImportCustomData: boolean;
/**
* Gets the parsed linearization information if available.
*
* @private
* @returns {_Linearization} The linearization helper if the document is linearized; otherwise, `undefined`.
*/
readonly _linearization: _Linearization;
/**
* Locates and returns the byte offset of the startxref section.
*
* @private
* @returns {number} The position of the last `startxref` marker; otherwise, 0 if not found.
*/
readonly _startXRef: number;
/**
* Gets a value indicating whether the document is encrypted. (Read Only).
*
* @returns {boolean} A boolean value indicates whether the document is encrypted.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Gets a value indicating whether the document is encrypted.
* let isEncrypted: boolean = document.isEncrypted;
* // Destroy the document
* document.destroy();
* ```
*/
readonly isEncrypted: boolean;
/**
* Gets a value indicating whether the document is decrypted using the user password. (Read only).
*
* @returns {boolean} A boolean value indicates whether the document is decrypted using the user password.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Gets a value indicating whether the document is decrypted using the user password
* let isUserPassword: boolean = document.isUserPassword;
* // Destroy the document
* document.destroy();
* ```
*/
readonly isUserPassword: boolean;
/**
* Gets the page count (Read only).
*
* @returns {number} Number of pages
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Gets the page count
* let count: number = document.pageCount;
* // Destroy the document
* document.destroy();
* ```
*/
readonly pageCount: number;
/**
* Gets the PDF form fields included in the document (Read only).
*
* @returns {PdfForm} Form object
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access loaded form
* let form: PdfForm = document.form;
* // Destroy the document
* document.destroy();
* ```
*/
readonly form: PdfForm;
/**
* Gets the boolean flag to flatten the annotations and form fields.
*
* @returns {boolean} Flag to flatten
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Gets the flatten value applied
* let flatten: boolean = document.flatten;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the boolean flag to flatten the annotations and form fields.
*
* @param {boolean} value to flatten
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Flatten PDF annotations and form fields
* document.flatten = true;
* // Destroy the document
* document.destroy();
* ```
*/
flatten: boolean;
/**
* Decompresses PDF stream bytes if they are compressed with a filter.
*
* @private
* @param {_PdfStream} stream The PDF stream to decompress.
* @returns {Uint8Array} The decompressed bytes, or original bytes if not compressed.
*/
_getDecompressedStreamBytes(stream: any): Uint8Array;
/**
* Gets the XMP metadata of the PDF document.
*
* @private
* @returns {PdfXmpMetadata} The XMP metadata object present.
*/
_getMetadataValue(): PdfXmpMetadata;
/**
* Gets the permission flag of the PDF document (Read only).
*
* @returns {PdfPermissionFlag} permission flag. Default value is PdfPermissionFlag.default.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Gets the permission flag
* let permission: PdfPermissionFlag = document.permissions;
* // Destroy the document
* document.destroy();
* ```
*/
readonly permissions: PdfPermissionFlag;
/**
* Gets the bookmarks (Read only).
*
* @returns {PdfBookmarkBase} Bookmarks.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get bookmarks
* let bookmarks: PdfBookmarkBase = document.bookmarks;
* // Destroy the document
* document.destroy();
* ```
*/
readonly bookmarks: PdfBookmarkBase;
/**
* Gets the internal structure of the PDF document.
*
* @returns {PdfFileStructure} The internal structure of the PDF document.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access the internal file structure of the PDF document
* let fileStructure: PdfFileStructure = document.fileStructure;
* // Get the cross reference type
* let type: PdfCrossReferenceType = fileStructure.crossReferenceType;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly fileStructure: PdfFileStructure;
/**
* Gets the collection of `PdfLayer` from the document.
*
* @returns {PdfLayerCollection} Layer collection.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access the collection of layers in the document
* let layers: PdfLayerCollection = document.layers;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly layers: PdfLayerCollection;
/**
* Gets the template configuration for document-level headers and footers.
*
* ```typescript
* // Create new document
* let document: PdfDocument = new PdfDocument();
* // Initialize the standard font
* const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
* / Initialize brush
* const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
* // Create header template
* let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({width: 500, height: 50});
* // Draw content on header
* headerTemplate.graphics.drawString('Document Header', font, {x: 10, y: 10, width: 400, height: 30}, brush);
* // Assign template to document
* document.template.top = {template: headerTemplate };
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @returns {PdfDocumentTemplate} The document template.
*/
readonly template: PdfDocumentTemplate;
/**
* Gets an array of revision numbers for the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Retrieve all revision indexes of the PDF document
* let revisions: number[] = document.getRevisions();
* // Destroy the document
* document.destroy();
* ```
*
* @returns {number[]} - The list of revisions in the document.
*/
getRevisions(): number[];
/**
* Embed a standard font into the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Embed a font into the PDF document.
* const embedFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
* // Draw string using embed font.
* page.graphics.drawString('value', embedFont, {x: 10, y: 10, width: 100, height: 100}, new PdfBrush({r: 255, g: 0, b: 0}));
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfFontFamily} fontFamily The font family.
* @param {number} size The font size.
* @param {PdfFontStyle } style The font style.
* @returns {PdfStandardFont} The embedded font object.
*/
embedFont(fontFamily: PdfFontFamily, size: number, style: PdfFontStyle): PdfStandardFont;
/**
* Embed a Cjk font into the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Embed a font into the PDF document with CJK embedding enabled.
* const embedFont = document.embedFont(PdfCjkFontFamily.hanyangSystemsGothicMedium, 14, PdfFontStyle.bold, true);
* // Draw string using embed font.
* page.graphics.drawString('value', embedFont, {x: 10, y: 10, width: 100, height: 100});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfCjkFontFamily} fontFamily The Cjk font family.
* @param {number} size The font size.
* @param {PdfFontStyle} style The font style.
* @param {boolean} isCjk Set to true by default to embed the font as a CJK font.
* @returns {PdfCjkStandardFont} The embedded font object.
*/
embedFont(fontFamily: PdfCjkFontFamily, size: number, style: PdfFontStyle, isCjk: true): PdfCjkStandardFont;
/**
* Embed a true type font into the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Embed a font into the PDF document.
* let embedFont = document.embedFont(fontData, 14, { shouldUnderline: true });
* // Draw string using embed font.
* page.graphics.drawString('value', embedFont, {x: 10, y: 10, width: 100, height: 100});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {Uint8Array} fontData The font data as byte array.
* @param {number} size The font size.
* @param {object} options Optional object containing font style options.
* @param {boolean} options.shouldUnderline Indicates whether the font should be rendered with an underline style.
* @param {boolean} options.shouldStrikeout Indicates whether the font should be rendered with a strikeout style.
* @return {PdfTrueTypeFont} The embedded font object.
*/
embedFont(fontData: Uint8Array, size: number, options?: {
shouldUnderline?: boolean;
shouldStrikeout?: boolean;
}): PdfTrueTypeFont;
/**
* Embed a true type font into the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Embed a font into the PDF document.
* let embedFont = document.embedFont(fontData, 14, { shouldStrikeout: true });
* // Draw string using embed font.
* page.graphics.drawString('value', embedFont, {x: 10, y: 10, width: 100, height: 100});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string } fontData The font data as base64 string.
* @param {number} size The font size.
* @param {object} options Optional object containing font style options.
* @param {boolean} options.shouldUnderline Indicates whether the font should be rendered with an underline style.
* @param {boolean} options.shouldStrikeout Indicates whether the font should be rendered with a strikeout style.
* @return {PdfTrueTypeFont} The embedded font object.
*/
embedFont(fontData: string, size: number, options?: {
shouldUnderline?: boolean;
shouldStrikeout?: boolean;
}): PdfTrueTypeFont;
/**
* Creates or retrieves a font primitive for the specified key and font data.
*
* @private
* @param {string} key Unique key used to cache the font primitive.
* @param {_FontData} fontData Font descriptor and/or data used to build a font primitive.
* @returns {_PdfFontPrimitive} The created or cached font primitive.
*/
_getOrCreateFontPrimitive(key: string, fontData: _FontData): _PdfFontPrimitive;
/**
* Creates a concrete `PdfFont` from a font primitive and style/size.
*
* @private
* @param {_PdfFontPrimitive} primitive The source font primitive.
* @param {number} size The font size.
* @param {PdfFontStyle} style The font style.
* @returns {PdfFont} The created font wrapper object.
*/
_createFontFromPrimitive(primitive: _PdfFontPrimitive, size: number, style: PdfFontStyle): PdfFont;
/**
* Computes a stable hash for font data (MD5 hex).
*
* @private
* @param {Uint8Array} fontData Raw font bytes.
* @returns {string} Hex-encoded MD5 hash of the font bytes.
*/
_computeFontHash(fontData: Uint8Array): string;
/**
* Gets the `PdfPage` at the specified index.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {number} pageIndex Page index.
* @returns {PdfPage} PDF page at the specified index.
*/
getPage(pageIndex: number): PdfPage;
/**
* Creates a new page with default page settings and adds it to the collection.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Add a new PDF page
* let page: PdfPage = document.addPage();
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @returns {PdfPage} PDF page at the specified index.
*/
addPage(): PdfPage;
/**
* Creates a new page with default settings and inserts it into the collection at the specified page index.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create and insert a new PDF page at 5th index
* let page: PdfPage = document.addPage(5);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {number} index Page index.
* @returns {PdfPage} PDF page at the specified index.
*/
addPage(index: number): PdfPage;
/**
* Creates a new page with specified page settings and adds it to the collection.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfPageSettings} pageSettings Page settings.
* @returns {PdfPage} PDF page at the specified index.
*/
addPage(pageSettings: PdfPageSettings): PdfPage;
/**
* Creates a new page with specified page settings and inserts it into the collection at the specified page index.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Create and insert a new PDF page at 5th index with specified page settings
* page = document.addPage(5, pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {number} index Page index.
* @param {PdfPageSettings} pageSettings Page settings.
* @returns {PdfPage} PDF page at the specified index.
*/
addPage(index: number, pageSettings: PdfPageSettings): PdfPage;
/**
* Creates a new section with default page settings.
*
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new section to the document
* let section: PdfSection = document.addSection();
* // Add a new page to the section
* let page: PdfPage = section.addPage();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a new pen.
* let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
* // Draw line on the page graphics.
* graphics.drawLine(pen, {x: 10, y: 10}, {x: 100, y: 100});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @returns {PdfSection} section of document
*/
addSection(): PdfSection;
/**
* Creates a new section with custom page settings.
*
* ```typescript
* // Create an new PDF document
* let document: PdfDocument = new PdfDocument();
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new section to the document with page settings
* let section: PdfSection = document.addSection(pageSettings);
* // Add a new page to the section
* let page: PdfPage = section.addPage();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a new pen.
* let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
* // Draw line on the page graphics.
* graphics.drawLine(pen, {x: 10, y: 10}, {x: 100, y: 100});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfPageSettings} settings Settings of the section.
* @returns {PdfSection} section of document
*/
addSection(settings: PdfPageSettings): PdfSection;
/**
* Removes the specified page.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access the first page
* let page: PdfPage = document.getPage(0);
* // Removes the specified page
* document.removePage(page);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfPage} page The page to remove.
*/
removePage(page: PdfPage): void;
/**
* Removes the page from the specified index.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Removes the first page
* document.removePage(0);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {number} index The page index to remove.
*/
removePage(index: number): void;
/**
* Gets the document information of the PDF.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Gets the document information of the PDF
* let documentProperties: PdfDocumentInformation = document.getDocumentInformation();
* // Gets the title of the PDF document
* let title = documentProperties.title;
* // Gets the author of the PDF document
* let author = documentProperties.author;
* // Gets the subject of the PDF document
* let subject = documentProperties.subject;
* // Gets the keywords of the PDF document
* let keywords = documentProperties.keywords;
* // Gets the creator of the PDF document
* let creator = documentProperties.creator;
* // Gets the producer of the PDF document
* let producer = documentProperties.producer;
* // Gets the language of the PDF document
* let language = documentProperties.language;
* // Gets the creation date of the PDF document
* let creationDate = documentProperties.creationDate;
* // Gets the modification date of the PDF document
* let modificationDate = documentProperties.modificationDate;
* document.destroy();
* ```
*
* @param {boolean} skipMetadata flag value to skip the metadata.
* @returns {PdfDocumentInformation} Document information.
*/
getDocumentInformation(skipMetadata?: boolean): PdfDocumentInformation;
private _readInfoString;
/**
* Sets the document information of the PDF.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets the document information of the PDF
* document.setDocumentInformation({
* author: 'Syncfusion',
* modificationDate: Date.now(),
* creator: 'Essential PDF',
* keywords: 'PDF',
* subject: 'Document information DEMO',
* title: 'Essential PDF Sample',
* producer: 'Syncfusion PDF'
* });
* // Save the document
* document.save('output.pdf);
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfDocumentInformation} information Fields to set.
* @returns {void} Returns nothing.
*/
setDocumentInformation(information: PdfDocumentInformation): void;
/**
* Writes a string value into the document information dictionary.
*
* @private
* @param {_PdfDictionary} dict Target dictionary.
* @param {string} key Info key to update.
* @param {string} [value] String value to write if defined.
* @returns {void} nothing.
*/
_writeInfoString(dict: _PdfDictionary, key: string, value?: string): void;
/**
* Writes a date value into the document information dictionary.
*
* @private
* @param {_PdfDictionary} dict Target dictionary.
* @param {string} key Info key to update.
* @param {Date} [value] Date value to write if provided.
* @returns {void} nothing.
*/
_writeInfoDate(dict: _PdfDictionary, key: string, value?: Date): void;
private _getInfoDictionary;
/**
* Validates a page index against the current page count.
*
* @private
* @param {number} index Zero-based page index to validate.
* @returns {void} nothing.
*/
_checkPageNumber(index: number): void;
/**
* Rebuilds the pages cache after insertion or removal and updates page indices.
*
* @private
* @param {number} index The index at which pages were inserted or removed.
* @param {boolean} [isIncrement=true] Set to `true` when inserting; set to `false` when removing.
* @returns {void} nothing.
*/
_updatePageCache(index: number, isIncrement?: boolean): void;
/**
* Removes the specified page and updates bookmarks, templates, form fields, and page tree.
*
* @private
* @param {PdfPage} pageToRemove The page to remove from the document.
* @returns {void} nothing.
*/
_removePage(pageToRemove: PdfPage): void;
/**
* Removes a page reference from its parents Kids array and updates page counts accordingly.
*
* @private
* @param {_PdfReference} referenceToRemove The page indirect reference to remove.
* @param {_PdfDictionary} dictionary The page dictionary whose parent will be updated.
* @returns {void} nothing.
*/
_removeParent(referenceToRemove: _PdfReference, dictionary: _PdfDictionary): void;
/**
* Builds and returns a map of pages to the bookmarks that reference them.
*
* @private
* @returns {Map<PdfPage, PdfBookmarkBase[]>} A map of pages to associated bookmark nodes.
*/
_parseBookmarkDestination(): Map<PdfPage, PdfBookmarkBase[]>;
/**
* Removes template/name entries associated with the specified page from the names dictionary.
*
* @private
* @param {PdfPage} page The page whose template/name entries should be removed.
* @returns {void} nothing.
*/
_removePageTemplates(page: PdfPage): void;
/**
* Removes entries from a particular names tree (by key) that reference the specified page.
*
* @private
* @param {_PdfDictionary} dictionary The root names dictionary.
* @param {string} key The names tree key to update (for example, 'Pages' or 'Templates').
* @param {PdfPage} page The page used to filter out entries.
* @returns {void} nothing.
*/
_removeInternalTemplates(dictionary: _PdfDictionary, key: string, page: PdfPage): void;
/**
* Returns a filtered Names array with entries for the specified page removed.
*
* @private
* @param {_PdfDictionary[]} namedPages The original Names array entries.
* @param {PdfPage} page The page whose entries should be removed.
* @returns {_PdfDictionary[]} The updated Names array without the specified page entries.
*/
_getUpdatedPageTemplates(namedPages: _PdfDictionary[], page: PdfPage): _PdfDictionary[];
/**
* Reorders the pages in the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Reorders the pages in the PDF document
* document.reorderPages([3, 2, 1]);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {number[]} orderArray The page sequence to arrange the pages.
* @returns {void} Nothing.
*/
reorderPages(orderArray: number[]): void;
/**
* Returns a distinct array preserving the first occurrence order.
*
* @private
* @param {number[]} order Array of page indexes to deduplicate.
* @returns {number[]} The deduplicated array in original order.
*/
_sortedArray(order: number[]): number[];
/**
* Clones resource dictionaries from source to target, merging entries where appropriate.
*
* @private
* @param {_PdfDictionary} source Source resource dictionary.
* @param {_PdfDictionary} target Target page/section dictionary to receive merged resources.
* @returns {void} nothing.
*/
_cloneResources(source: _PdfDictionary, target: _PdfDictionary): void;
/**
* Merges nested resource entries (dictionaries or arrays) into a target resource dictionary.
*
* @private
* @param {string} key Resource key to merge.
* @param {any} value Incoming resource value (dictionary or array).
* @param {_PdfDictionary} resourceDictionary Target resource dictionary to update.
* @returns {void} nothing.
*/
_cloneInnerResources(key: string, value: any, resourceDictionary: _PdfDictionary): void;
/**
* Saves the modified document synchronously.
*
* @remarks
* This method does **not** support embedding a timestamped digital signature.
* To embed a timestamp from a trusted timestamp authority (TSA), use the asynchronous saveAsync() method.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Save the document
* let data: Uint8Array = document.save();
* // Destroy the document
* document.destroy();
* ```
*
* @returns {Uint8Array} Saved PDF data as byte array.
*/
save(): Uint8Array;
/**
* Saves the modified document to the specified filename.
*
* @remarks
* This method does **not** support embedding a timestamped digital signature.
* To embed a timestamp from a trusted timestamp authority (TSA), use the asynchronous saveAsync(filename) method.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Save the document
* document.save('Output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} filename Specifies the filename to save the output pdf document.
* @returns {void}
*/
save(filename: string): void;
/**
* Saves the PDF document asynchronously and returns the resulting bytes.
*
* @example
* ```typescript
* // Load the document
* let document: PdfDocument = new PdfDocument(data);
* // Gets the first page of the document
* let page: PdfPage = document.getPage(0);
* // Access the PDF form
* let form: PdfForm = document.form;
* // Create a new signature field
* let field: PdfSignatureField = new PdfSignatureField(page, 'Signature', {x: 10, y: 10, width: 100, height: 50});
* // Create a timestamp callback
* async function timestampCallback(request: Uint8Array): Promise<{ response: Uint8Array }> {
* // Implement timestamp response logic here
* return new Uint8Array(); // Placeholder return
* }
* // Create a new signature using PFX data, private key and call back function for timestamp
* const sign: PdfSignature = PdfSignature.create(certData, password, { cryptographicStandard: CryptographicStandard.cms, digestAlgorithm: DigestAlgorithm.sha256 }, timestampCallback);
* // Sets the signature to the field
* field.setSignature(sign);
* // Add the field into PDF form
* form.add(field);
* // Save the document
* const data = await document.saveAsync();
* // Destroy the document
* document.destroy();
* ```
*
* @returns {Promise<Uint8Array>} The saved PDF data as a byte array.
*/
saveAsync(): Promise<Uint8Array>;
/**
* Saves the PDF document asynchronously to the specified filename.
*
* @example
* ```typescript
* // Load the document
* let document: PdfDocument = new PdfDocument(data);
* // Gets the first page of the document
* let page: PdfPage = document.getPage(0);
* // Access the PDF form
* let form: PdfForm = document.form;
* // Create a new signature field
* let field: PdfSignatureField = new PdfSignatureField(page, 'Signature', {x: 10, y: 10, width: 100, height: 50});
* // Create a timestamp callback
* async function timestampCallback(request: Uint8Array): Promise<{ response: Uint8Array }> {
* // Implement timestamp response logic here
* return new Uint8Array(); // Placeholder return
* }
* // Create a new signature using PFX data, private key and call back function for timestamp
* const sign: PdfSignature = PdfSignature.create(certData, password, { cryptographicStandard: CryptographicStandard.cms, digestAlgorithm: DigestAlgorithm.sha256 }, timestampCallback);
* // Sets the signature to the field
* field.setSignature(sign);
* // Add the field into PDF form
* form.add(field);
* // Save the document
* await document.saveAsync('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} filename The target filename to write the output PDF.
* @returns {Promise<void>} Resolves when the file has been saved.
*/
saveAsync(filename: string): Promise<void>;
/**
* Saves the document to the specified output stream and return the stream as Blob.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Save the document
* let data: Promise<{ blobData: Blob }> = document.saveAsBlob();
* // Destroy the document
* document.destroy();
* ```
*
* @returns {Promise<{ blobData: Blob }>} Saved PDF data as `Blob`.
*/
saveAsBlob(): Promise<{
blobData: Blob;
}>;
/**
* Exports the annotations from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Exports the annotations from the PDF document.
* let data: Uint8Array = document.exportAnnotations();
* // Destroy the document
* document.destroy();
* ```
*
* @returns {Uint8Array} Exported annotation data as byte array.
*/
exportAnnotations(): Uint8Array;
/**
* Exports the annotations from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets export data format as JSON type to annotation export settings
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* settings.dataFormat = DataFormat.json;
* // Export annotations to JSON format
* let json: Uint8Array = document.exportAnnotations(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfAnnotationExportSettings} settings Annotation export settings.
* @returns {Uint8Array} Exported annotation data as byte array.
*/
exportAnnotations(settings: PdfAnnotationExportSettings): Uint8Array;
/**
* Exports the annotations from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Exports the annotations from the PDF document.
* document.exportAnnotations('annotations.xfdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} filename Output file name.
* @returns {void} Exports the annotations from the PDF document.
*/
exportAnnotations(filename: string): void;
/**
* Exports the annotations from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets export data format as JSON type to annotation export settings
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* settings.dataFormat = DataFormat.json;
* // Export annotations to JSON format
* let json: Uint8Array = document.exportAnnotations('annotations.json', settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} filename Output file name.
* @param {PdfAnnotationExportSettings} settings Annotation export settings.
* @returns {void} Exports the annotations from the PDF document.
*/
exportAnnotations(filename: string, settings: PdfAnnotationExportSettings): void;
/**
* Exports the form data from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Exports the form data from the PDF document.
* let data: Uint8Array = document.exportFormData();
* // Destroy the document
* document.destroy();
* ```
*
* @returns {Uint8Array} Exported form data as byte array.
*/
exportFormData(): Uint8Array;
/**
* Exports the form data from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with output data format.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* settings.dataFormat = DataFormat.json;
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfFormFieldExportSettings} settings Form field export settings.
* @returns {Uint8Array} Exported form data as byte array.
*/
exportFormData(settings: PdfFormFieldExportSettings): Uint8Array;
/**
* Exports the form data from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Export form field to XFDF format
* let xfdf: Uint8Array = document.exportFormData('formData.xfdf');
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} filename Output file name.
* @returns {void} Exports the form data from the PDF document.
*/
exportFormData(filename: string): void;
/**
* Exports the form data from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with output data format.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* settings.dataFormat = DataFormat.json;
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData('formData.json', settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} filename Output file name.
* @param {PdfFormFieldExportSettings} settings Form field export settings.
* @returns {void} Exports the form data from the PDF document.
*/
exportFormData(filename: string, settings: PdfFormFieldExportSettings): void;
/**
* Imports the annotations from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Imports annotations from to the PDF document.
* document.importAnnotations('annotations.json', DataFormat.json);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} data annotations data as base64 string.
* @param {DataFormat} dataFormat Data format of the input data.
* @returns {void} Imports the annotations to the PDF document.
*/
importAnnotations(data: string, dataFormat: DataFormat): void;
/**
* Imports the annotations from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Imports annotations from to the PDF document.
* document.importAnnotations(annotations, DataFormat.json);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {Uint8Array} data annotations data as byte array.
* @param {DataFormat} dataFormat Data format of the input data.
* @returns {void} Imports the annotations to the PDF document.
*/
importAnnotations(data: Uint8Array, dataFormat: DataFormat): void;
/**
* Imports the form data from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Imports form data from to the PDF document.
* document.importFormData('formData.json', DataFormat.json);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {string} data Form data as base64 string.
* @param {DataFormat} dataFormat Data format of the input data.
* @returns {void} Imports the form data to the PDF document.
*/
importFormData(data: string, dataFormat: DataFormat): void;
/**
* Imports the form data from the PDF document.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Imports form data from to the PDF document.
* document.importFormData(data, DataFormat.json);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {Uint8Array} data Form data as byte array.
* @param {DataFormat} dataFormat Data format of the input data.
* @returns {void} Imports the form data to the PDF document.
*/
importFormData(data: Uint8Array, dataFormat: DataFormat): void;
/**
* Disposes the current instance of `PdfDocument` class.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Destroy the document
* document.destroy();
* ```
*
* @returns {void} Nothing.
*/
destroy(): void;
/**
* Lazily retrieves the named destination collection from the document catalog.
*
* @private
* @returns {_PdfNamedDestinationCollection} The named destination collection.
*/
readonly _destinationCollection: _PdfNamedDestinationCollection;
/**
* Retrieves the linearization page dictionary and reference for the given page index.
*
* @private
* @param {number} pageIndex - The zero-based index of the page to retrieve.
* @returns {{dictionary: _PdfDictionary, reference: _PdfReference}} returns reference .
*/
_getLinearizationPage(pageIndex: number): {
dictionary: _PdfDictionary;
reference: _PdfReference;
};
/**
* Validates and reads the document header to determine the PDF version and update file structure.
*
* @private
* @returns {void} nothing.
*/
_checkHeader(): void;
/**
* Parses cross-reference sections and builds the catalog.
*
* @private
* @param {boolean} recoveryMode Set `true` to enable fallback parsing strategies.
* @returns {void} nothing.
*/
_parse(recoveryMode: boolean): void;
/**
* Searches the given stream for a signature within a byte limit.
*
* @private
* @param {_PdfStream} stream The stream to scan.
* @param {Uint8Array} signature The byte signature to locate.
* @param {number} [limit=1024] Max number of bytes to scan.
* @param {boolean} [backwards=false] If `true`, scans from the end backwards.
* @returns {boolean} `true` if the signature is found; otherwise, `false`.
*/
_find(stream: _PdfStream, signature: Uint8Array, limit?: number, backwards?: boolean): boolean;
/**
* Performs post-processing for forms and annotations, optionally flattening them.
*
* @private
* @param {boolean} [isFlatten=false] Set `true` to flatten annotations and form fields.
* @returns {void} nothing.
*/
_doPostProcess(isFlatten?: boolean): void;
/**
* Adds XMP metadata stream to the PDF document catalog.
*
* @private
* @returns {void} nothing.
*/
_addXmpMetadata(): void;
/**
* Renders document templates (headers/footers) onto all pages for the specified layer mode.
*
* @private
* @param {PdfTemplateLayerMode} mode The template layer mode to render (background|foreground|undefined for default).
* @returns {void} Nothing.
*/
_renderDocumentTemplates(mode: PdfTemplateLayerMode): void;
/**
* Renders templates for a specific page based on odd/even precedence.
*
* @private
* @param {PdfPage} page The page to render templates on.
* @param {boolean} isOddPage Whether the page is odd-numbered.
* @param {PdfTemplateLayerMode | undefined} mode The template layer mode to render (background|foreground|undefined for default).
* @returns {void} Nothing.
*/
_renderPageTemplates(page: PdfPage, isOddPage: boolean, mode: PdfTemplateLayerMode): void;
/**
* Gets the index of the section that contains the specified page reference.
*
* @param {_PdfReference} parentRef - The reference of the page's parent section.
* @returns {number} The zero-based index of the matching section, or -1 if not found.
* @private
*/
_getSectionIndexByPage(parentRef: _PdfReference): number;
/**
* Renders a `PdfTemplate` into the page contents as a form XObject (foreground).
* This method creates a content stream that places and scales the template
* to the provided `bounds`, registers the template as an XObject resource,
* and appends the resulting content stream to the page contents.
*
* @private
* @param {PdfPage} page The target page to draw the template onto.
* @param {PdfTemplate} template The template to render as an XObject.
* @param {Rectangle} bounds The bounds on the page where the template should be drawn.
* @returns {void} Nothing.
*/
private _drawForegroundTemplate;
/**
* Gets the appropriate template and alignment for the specified side based on odd or even page.
*
* @private
* @param {_TemplateSide} side The template side (top, bottom, left, or right).
* @param {boolean} isOddPage Whether the current page is odd-numbered.
* @param {number} sectionIndex The section index to resolve section-specific templates or -1 if not applicable.
* @returns {Object} The resolved template information, template layer mode and alignment, or null if none is found.
*/
private _getTemplateForSide;
/**
* Retrieves template object by template key.
*
* @private
* @param {_PdfDocumentTemplateKey} key The template key.
* @returns {any} The template object or undefined.
*/
private _getTemplateByKey;
/**
* Gets the appropriate template and alignment for a section.
*
* @param {PdfSection} section The section to get the template from.
* @param {_TemplateSide} side The template side.
* @param {boolean} isOddPage Whether the page is odd-numbered.
* @returns {Object} The resolved template info, or null if none is found.
* @private
*/
private _getSectionTemplateForSide;
/**
* Gets the alignment position for a template on a page.
*
* @private
* @param {PdfPage} page The target page on which the template will be positioned.
* @param {PdfDocumentTemplate} documentTemplate The document template containing the template elements.
* @param {PdfTemplateHorizontalAlignment | PdfTemplateVerticalAlignment | undefined} alignment Specifies the alignment
* (horizontal or vertical) used to position the template within the page.
* @param {_TemplateSide} side Specifies the side of the page (such as top, bottom, left, or right)
* where the template should be placed.
* @param {boolean} isOddPage Indicates whether the current page is an odd-numbered page,
* which may affect template placement (e.g., for mirrored layouts).
* @returns {{ x: number, y: number, width: number, height: number }} An object representing
* the calculated position (x, y) and dimensions (width, height) of the template.
*/
_getTemplateAlignmentPosition(page: PdfPage, documentTemplate: PdfDocumentTemplate, alignment: PdfTemplateHorizontalAlignment | PdfTemplateVerticalAlignment | undefined, side: _TemplateSide, isOddPage: boolean): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Gets alignment bounds for a template.
*
* @private
* @param {_TemplateSide} side The template side.
* @param {PdfPageTemplateElement} template The template element.
* @param {PdfPage} page The page.
* @param {PdfTemplateHorizontalAlignment | PdfTemplateVerticalAlignment | undefined} alignment The alignment.
* @returns {Rectangle} The alignment bounds.
*/
_getAlignmentBounds(side: _TemplateSide, template: PdfPageTemplateElement, page: PdfPage, alignment: PdfTemplateHorizontalAlignment | PdfTemplateVerticalAlignment | undefined): Rectangle;
/**
* Converts template side enum to string for legacy compatibility.
*
* @private
* @param {_TemplateSide} side The template side enum.
* @returns {string} The side as string ('top', 'bottom', 'left', 'right').
*/
private _templateSideToString;
/**
* Normalizes a document template key or template side into its corresponding
* base template side (Top, Bottom, Left, or Right).
*
* @private
* @param {_PdfDocumentTemplateKey | _TemplateSide} key
* The document template key or template side to normalize.
* @returns {_TemplateSide} The normalized base template side.
*/
private _normalizeTemplateSide;
/**
* Resolves the effective template alignment style based on the document template key
* (including odd/even variants) and the specified horizontal or vertical alignment.
*
* @private
* @param {_PdfDocumentTemplateKey | _TemplateSide} templateKey
* The document template key or normalized template side used to determine alignment context.
* @param {PdfTemplateHorizontalAlignment | PdfTemplateVerticalAlignment} alignment
* The alignment value applied to the template.
* @returns {_PdfAlignmentStyle} The resolved alignment style for positioning the template.
*/
private _mapTemplateAlignmentStyle;
/**
* Gets the template alignment bounds based on alignment style.
*
* @private
* @param {PdfPageTemplateElement} template The template element.
* @param {PdfPage} page The page.
* @param {_PdfAlignmentStyle} alignmentStyle The alignment style enum.
* @param {_TemplateSide} [side] Optional template side for context-specific positioning.
* @returns {Rectangle} The alignment bounds.
*/
_getTemplateAlignmentBounds(template: PdfPageTemplateElement, page: PdfPage, alignmentStyle: _PdfAlignmentStyle, side?: _TemplateSide): Rectangle;
/**
* Checks if a template should not reserve space (background or foreground templates).
*
* @param {PdfTemplateLayerMode} templateLayerMode Template layer mode.
* @returns {boolean} True if the template should not reserve space.
* @private
*/
private _isNonReservingTemplate;
/**
* Calculates the left indent width reserved by page templates and optional page margins.
*
* @private
* @param {PdfPage} page The page to compute the left indent for.
* @param {boolean} includeMargins If true, include the page left margin in the returned width.
* @returns {number} The total left indent width (in points).
*/
_getLeftIndentWidth(page: PdfPage, includeMargins: boolean): number;
/**
* Calculates the top indent height reserved by page templates and optional page margins.
*
* @private
* @param {PdfPage} page The page to compute the top indent for.
* @param {boolean} includeMargins If true, include the page top margin in the returned height.
* @returns {number} The total top indent height (in points).
*/
_getTopIndentHeight(page: PdfPage, includeMargins: boolean): number;
/**
* Calculates the right indent width reserved by page templates and optional page margins.
*
* @private
* @param {PdfPage} page The page to compute the right indent for.
* @param {boolean} includeMargins If true, include the page right margin in the returned width.
* @returns {number} The total right indent width (in points).
*/
_getRightIndentWidth(page: PdfPage, includeMargins: boolean): number;
/**
* Calculates the bottom indent height reserved by page templates and optional page margins.
*
* @private
* @param {PdfPage} page The page to compute the bottom indent for.
* @param {boolean} includeMargins If true, include the page bottom margin in the returned height.
* @returns {number} The total bottom indent height (in points).
*/
_getBottomIndentHeight(page: PdfPage, includeMargins: boolean): number;
/**
* Calculates the docking bounds for a page template based on the specified dock position.
*
* @private
* @param {PdfPage} page The page on which the template is being positioned.
* @param {PdfPageTemplateElement} template The template element to dock.
* @param {string} dock The dock position applied to the template ('left', 'top', 'right', or 'bottom').
* @returns {Rectangle} The calculated bounds of the docked template.
*/
_getTemplateDockBounds(page: PdfPage, template: PdfPageTemplateElement, dock: string): Rectangle;
/**
* Finalizes form fields, optionally flattening and updating appearance flags.
*
* @private
* @param {boolean} [isFlatten=false] Set `true` to flatten form fields.
* @returns {void} nothing.
*/
_doPostProcessOnFormFields(isFlatten?: boolean): void;
/**
* Finalizes annotations for all pages, optionally flattening them.
*
* @private
* @param {boolean} [isFlatten=false] Set `true` to flatten annotations.
* @returns {void} nothing.
*/
_doPostProcessOnAnnotations(isFlatten?: boolean): void;
/**
* Adds the evaluation watermark text to all pages when license validation fails.
*
* @private
* @returns {void} nothing.
*/
_addWatermarkText(): void;
/**
* Add license watermark on the page.
*
* @private
* @param { PdfPage } page PDF-page.
* @param { boolean } isFirstPage It denotes it is a first page or not.
* @param { boolean } isLastPage It denotes it is a last page or not.
* @returns { void } Returns void
*/
private _addLincenseWaterMark;
/**
* Draw the watermark in the header and footer of the page.
*
* @private
* @param { PdfPage } page PDF-page.
* @param { PdfStandardFont } font It denotes the font for the text added.
* @param { PdfGraphics } graphics It denotes the graphis of the page.
* @param { boolean } isLastPage It denotes it is a last page or not.
* @returns {void} Returns void.
*/
private _drawWatermarkOnPage;
/**
* Import the pages specified by the start and end index into the current document's pages collection.
*
* ```typescript
* // Load an existing PDF document
* let destination: PdfDocument = new PdfDocument(data1);
* // Load another existing PDF document
* let sourceDocument: PdfDocument = new PdfDocument(data2);
* // Import 5 pages from page index 2 to 6 into the destination document.
* destination.importPageRange(sourceDocument, 2, 6);
* // Save the output PDF
* destination.save('Output.pdf');
* // Destroy the documents
* destination.destroy();
* sourceDocument.destroy();
* ```
*
* @param {PdfDocument} sourceDocument PDF document to get pages to import.
* @param {number} startIndex Start page index. The default value is 0.
* @param {number} endIndex End page index. The default value is the index of the last page in the source document.
* @remarks The source document must be disposed of after the destination document is saved during the import function.
*/
importPageRange(sourceDocument: PdfDocument, startIndex: number, endIndex: number): void;
/**
* Import the pages specified by start and end index into the current document's pages collection.
*
* ```typescript
* // Load an existing PDF document
* let destination: PdfDocument = new PdfDocument(data1);
* // Load another existing PDF document
* let sourceDocument: PdfDocument = new PdfDocument(data2);
* // Options to customize the support of import PDF pages.
* let options: PdfPageImportOptions = new PdfPageImportOptions();
* // Sets the target page index to import
* options.targetIndex = 3;
* // Import 5 pages from page index 2 to 6 into the destination document and insert them at index 3.
* destination.importPageRange(sourceDocument, 2, 6, options);
* // Save the output PDF
* destination.save('Output.pdf');
* // Destroy the documents
* destination.destroy();
* sourceDocument.destroy();
* ```
*
* @param {PdfDocument} sourceDocument PDF document to get pages to import.
* @param {number} startIndex Start page index. The default value is 0.
* @param {number} endIndex End page index. The default value is the index of the last page in the source document.
* @param {PdfPageImportOptions} options Options to customize the support of import PDF pages.
* @remarks The source document must be disposed of after the destination document is saved during the import function.
*/
importPageRange(sourceDocument: PdfDocument, startIndex: number, endIndex: number, options?: PdfPageImportOptions): void;
/**
* Imports pages from the specified source document into this document.
*
* @private
* @param {PdfDocument} sourceDocument - The source PDF document to import pages from.
* @param {number} startIndex - The starting page index in the source document.
* @param {number} endIndex - The ending page index in the source document.
* @param {PdfPageImportOptions} [options] - Optional settings that control import behavior.
* @returns {void} nothing.
*/
_importPages(sourceDocument: PdfDocument, startIndex: number, endIndex: number, options?: PdfPageImportOptions): void;
/**
* Copy the specific page and insert it as the next page
*
* ```typescript
* // Load an existing PDF document
* let sourceDocument: PdfDocument = new PdfDocument(data1);
* // Copy the second page and add it as third page
* sourceDocument.importPage(1);
* // Save the output PDF
* sourceDocument.save('Output.pdf');
* // Destroy the documents
* sourceDocument.destroy();
* ```
*
* @param {number} pageIndex Target page index to import.
*/
importPage(index: number): void;
/**
* Copy the specific page and insert it at the specified target page index and page rotation.
*
* ```typescript
* // Load an existing PDF document
* let sourceDocument: PdfDocument = new PdfDocument(readFromResources('PDF_Succinctly.pdf'));
* // Options to customize the support of import PDF pages.
* let options: PdfPageImportOptions = new PdfPageImportOptions();
* // Sets the target page index to import
* options.targetIndex = 1;
* // Sets the rotation angle of the page to import
* options.rotation = PdfRotationAngle.angle180;
* // Copy the first page and add it as second page with page rotation
* sourceDocument.importPage(0, options);
* // Save the output PDF
* let output = sourceDocument.save();
* write('863764-86.pdf', output);
* // Destroy the documents
* sourceDocument.destroy();
* ```
*
* @param {number} pageIndex Target page index to import.
* @param {PdfPageImportOptions} options Options to customize the support of import PDF pages.
*/
importPage(index: number, options: PdfPageImportOptions): void;
/**
* Import the specified page into the current document pages collection as the last page
*
* ```typescript
* // Load an existing PDF document
* let destination: PdfDocument = new PdfDocument(data1);
* // Load another existing PDF document
* let sourceDocument: PdfDocument = new PdfDocument(data2);
* // Access first page of the source document
* let pageToImport: PdfPage = sourceDocument.getPage(0);
* // Import the page into the destination document as the last page.
* destination.importPage(pageToImport, sourceDocument);
* // Save the output PDF
* destination.save('Output.pdf');
* // Destroy the documents
* destination.destroy();
* sourceDocument.destroy();
* ```
*
* @param {PdfPage} page Page to import.
* @param {PdfDocument} sourceDocument PDF document to get pages to import.
* @remarks The source document must be disposed of after the destination document is saved during the import function.
*/
importPage(page: PdfPage, sourceDocument: PdfDocument): void;
/**
* Create a new page with default settings and insert it into the collection at the specified page index.
*
* ```typescript
* // Load an existing PDF document
* let destination: PdfDocument = new PdfDocument(data1);
* // Load another existing PDF document
* let sourceDocument: PdfDocument = new PdfDocument(data2);
* // Access first page of the source document
* let pageToImport: PdfPage = sourceDocument.getPage(0);
* // Options to customize the support of import PDF pages.
* let options: PdfPageImportOptions = new PdfPageImportOptions();
* // Sets the target page index to import
* options.targetIndex = 5;
* // Imports the page into destination document as 5th page
* destination.importPage(pageToImport, sourceDocument, options);
* // Save the output PDF
* destination.save('Output.pdf');
* // Destroy the documents
* destination.destroy();
* sourceDocument.destroy();
* ```
*
* @param {PdfPage} page Page to import.
* @param {PdfDocument} sourceDocument PDF document to get pages to import.
* @remarks The source document must be disposed of after the destination document is saved during the import function.
*/
importPage(page: PdfPage, sourceDocument: PdfDocument, options?: PdfPageImportOptions): void;
/**
* Splitting a PDF file into individual pages.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* document.splitEvent = documentSplitEvent;
* // Split PDF document into individual pages
* document.split();
* // Event to invoke while splitting PDF document data
* function documentSplitEvent(sender: PdfDocument, args: PdfDocumentSplitEventArgs): void {
* Save.save('output_' + args.splitIndex + '.pdf', new Blob([args.pdfData], { type: 'application/pdf' }));
* }
* // Destroy the document
* document.destroy();
* ```
*
* @returns {void} Nothing
*/
split(): void;
/**
* Splits the PDF document into parts, each containing a maximum number of pages specified.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* document.splitEvent = documentSplitEvent;
* // Split PDF document by fixed number of pages
* document.splitByFixedNumber(1);
* // Event to invoke while splitting PDF document data
* function documentSplitEvent(sender: PdfDocument, args: PdfDocumentSplitEventArgs): void {
* Save.save('output_' + args.splitIndex + '.pdf', new Blob([args.pdfData], { type: 'application/pdf' }));
* }
* // Destroy the document
* document.destroy();
* ```
*
* @param {number} fixedNumber specifies the maximum number of pages in each split PDF. The default value is 1.
* @returns {void} Nothing
*/
splitByFixedNumber(fixedNumber: number): void;
/**
* Splits the PDF document into multiple parts based on the specified page ranges.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* document.splitEvent = documentSplitEvent;
* // Split PDF document by page ranges specified
* document.splitByPageRanges([[0, 4], [5, 9]]);
* // Event to invoke while splitting PDF document data
* function documentSplitEvent(sender: PdfDocument, args: PdfDocumentSplitEventArgs): void {
* Save.save('output_' + args.splitIndex + '.pdf', new Blob([args.pdfData], { type: 'application/pdf' }));
* }
* // Destroy the document
* document.destroy();
* ```
*
* @param {Array<number[]>} ranges The two dimensional number array specified for start and end page indexes to split PDF documents.
* @returns {void} Nothing
*/
splitByPageRanges(ranges: number[][]): void;
private _importDocumentPages;
private _invokeSplitEvent;
/**
* Retrieves and initializes a PDF signature instance from the given dictionary and field.
*
* @private
* @param {_PdfDictionary} dictionary - The signature dictionary from the PDF.
* @param {any} field - The associated form field containing the signature.
* @returns {PdfSignature} The initialized `PdfSignature` object.
*/
_getSignature(dictionary: _PdfDictionary, field: any): PdfSignature;
/**
* Determines whether the document has any template content (headers/footers) defined.
*
* @private
* @returns {boolean} `true` if the document has template content; otherwise, `false`.
*/
_hasTemplateContent(): boolean;
/**
* Gets a value indicating whether the document contains any header or footer templates.
*
* @private
* @returns {boolean} `true` if at least one template is defined; otherwise, `false`.
*/
readonly _hasTemplateContentValue: boolean;
}
/**
* Represents annotation export settings.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets export data format as JSON type to annotation export settings
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* // Set the data format defined in annotation export settings
* settings.dataFormat = DataFormat.json;
* // Export annotations to JSON format
* let json: Uint8Array = document.exportAnnotations(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfAnnotationExportSettings {
/**
* @private
*/
_format: DataFormat;
_exportAppearance: boolean;
/**
* Gets the data format defined in annotation export settings.
*
* @returns {DataFormat} - Returns the data format.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets export data format as JSON type to annotation export settings
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* // Export annotations to JSON format
* let json: Uint8Array = document.exportAnnotations(settings);
* // Get the data format defined in annotation export settings
* let dataFormat: DataFormat = settings.dataFormat;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the data format defined in annotation export settings.
*
* @param {DataFormat} format - Specifies the data format.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets export data format as JSON type to annotation export settings
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* // Set the data format defined in annotation export settings
* settings.dataFormat = DataFormat.json;
* // Export annotations to JSON format
* let json: Uint8Array = document.exportAnnotations(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
dataFormat: DataFormat;
/**
* Gets the boolean value indicating whether the appearance of a particular object can be exported or not.
*
* @returns {boolean} - Returns the boolean value.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets the annotation export settings with enabled export appearance.
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* // Export annotations to XFDF format
* let xfdf: Uint8Array = document.exportAnnotations(settings);
* // Get the boolean value indicating whether the appearance of a particular object can be exported or not
* let appearance: boolean = settings.exportAppearance;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the boolean value indicating whether the appearance of a particular object can be exported or not.
*
* @param {boolean} value - The boolean value.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Sets the annotation export settings with enabled export appearance.
* let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
* // Set the boolean value indicating whether the appearance of a particular object can be exported or not
* settings.exportAppearance = true;
* // Export annotations to XFDF format
* let xfdf: Uint8Array = document.exportAnnotations(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
exportAppearance: boolean;
}
/**
* Represents form fields export settings.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with output data format.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Set the data format defined in form field export settings.
* settings.dataFormat = DataFormat.json;
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfFormFieldExportSettings {
/**
* @private
*/
_format: DataFormat;
/**
* @private
*/
_exportName: string;
/**
* @private
*/
_asPerSpecification: boolean;
/**
* Gets the data format defined in form field export settings.
*
* @returns {DataFormat} - Returns the data format.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with output data format.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Get the data format defined in form field export settings
* let dataFormat: DataFormat = settings.dataFormat;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the data format defined in form field export settings.
*
* @param {DataFormat} format - Specifies the data format.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with output data format.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Set the data format defined in form field export settings.
* settings.dataFormat = DataFormat.json;
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
dataFormat: DataFormat;
/**
* Gets the export name defined in form field export settings.
*
* @returns {string} - Returns the string value.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with export name.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Get the export name defined in form field export settings
* let name: boolean = settings.exportName;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the export name defined in form field export settings.
*
* @param {string} name - Specifies the export name of the form.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the form field data export settings with export name.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Set the export name defined in form field export settings.
* settings.exportName = 'JobApplication'.
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
exportName: string;
/**
* Gets the boolean value indicating whether the data in a form field can be exported based on a certain specification.
*
* @returns {boolean} - Returns the boolean value.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the boolean value indicating whether the data in a form field can be exported based on a certain specification.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Get the boolean value indicating whether the data in a form field can be exported based on a certain specification.
* let asPerSpecification: boolean = settings.asPerSpecification;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the boolean value indicating whether the data in a form field can be exported based on a certain specification.
*
* @param {boolean} value - The boolean value.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Sets the boolean value indicating whether the data in a form field can be exported based on a certain specification.
* let settings: PdfFormFieldExportSettings = new PdfFormFieldExportSettings();
* // Set the boolean value indicating whether the data in a form field can be exported based on a certain specification.
* settings.asPerSpecification = true;
* // Export form field to JSON format
* let json: Uint8Array = document.exportFormData(settings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
asPerSpecification: boolean;
}
/**
* The class provides various settings related to PDF pages.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfPageSettings {
_orientation: PdfPageOrientation;
/**
* @private
*/
_size: Size;
/**
* @private
*/
_isOrientation: boolean;
/**
* @private
*/
_margins: PdfMargins;
/**
* @private
*/
_rotation: PdfRotationAngle;
/**
* Initializes a new instance of the `PdfPageSettings` class
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor();
/**
* Initializes a new instance of the `PdfPageSettings` class.
*
* @param {object} [options] Optional settings to initialize the page.
* @param {PdfPageOrientation} [options.orientation] Page orientation.
* @param {Size} [options.size] Page size.
* @param {PdfMargins} [options.margins] Page margins.
* @param {PdfRotationAngle} [options.rotation] Page rotation angle.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings with custom options
* let pageSettings = new PdfPageSettings({
* orientation: PdfPageOrientation.landscape,
* size: { width: 842, height: 595 },
* margins: new PdfMargins(40),
* rotation: PdfRotationAngle.angle90
* });
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Destroy the document
* document.destroy();
* ```
*/
constructor(options: {
orientation?: PdfPageOrientation;
size?: Size;
margins?: PdfMargins;
rotation?: PdfRotationAngle;
});
/**
* Gets the orientation of the page.
*
* @returns {PdfPageOrientation} The orientation.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the page size
* pageSettings.size = {width: 842, height: 595};
* // Gets the page orientation
* let orientation: PdfPageOrientation = pageSettings.orientation;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the orientation of the page.
*
* @param {PdfPageOrientation} value The orientation.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
orientation: PdfPageOrientation;
/**
* Gets the size of the page.
*
* @returns {Size} The width and height of the page as number array.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access the first page
* let page: PdfPage = document.getPage(0);
* // Gets the width and height of the PDF page as number array
* let size: Size = page.size;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the width and height of the page.
*
* @param {Size} value The width and height of the page as number array.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
size: Size;
/**
* Gets the margin value of the page.
*
* @returns {PdfMargins} PDF margins
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Gets the margins
* let margins: PdfMargins = pageSettings.margins;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the margin value of the page.
*
* @param {PdfMargins} value PDF margins
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
margins: PdfMargins;
/**
* Gets the rotation angle of the PDF page.
*
* @returns {PdfRotationAngle} PDF rotation angle
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Gets the rotation angle
* let rotation: PdfRotationAngle = pageSettings.rotation;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the rotation angle of the PDF page.
*
* @param {PdfRotationAngle} value PDF rotation angle
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the rotation angle
* pageSettings.rotation = PdfRotationAngle.angle90;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
rotation: PdfRotationAngle;
/**
* Updates the page size based on the specified dimensions while respecting the current orientation.
*
* @private
* @param {Size} size Page size with `width` and `height`.
* @returns {void} nothing.
*/
_updateSize(size: Size): void;
/**
* Updates the page size by applying the specified orientation to the current size.
*
* @private
* @param {PdfPageOrientation} orientation Page orientation to apply.
* @returns {void} nothing.
*/
_updateSize(orientation: PdfPageOrientation): void;
/**
* Recomputes the page orientation from the current size (portrait if height ≥ width; otherwise landscape).
*
* @private
* @returns {void} nothing.
*/
_updateOrientation(): void;
/**
* Computes the drawable content size by subtracting margins from the page size.
*
* @private
* @returns {number[]} A two-element array.
*/
_getActualSize(): number[];
}
/**
* A class representing PDF page margins.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfMargins {
/**
* Left margin value in points.
*
* @private
*/
_left: number;
/**
* Right margin value in points.
*
* @private
*/
_right: number;
/**
* Top margin value in points.
*
* @private
*/
_top: number;
/**
* Bottom margin value in points.
*
* @private
*/
_bottom: number;
/**
* Initializes a new instance of the `PdfMargins` class.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor();
/**
* Initializes a new instance with specified margin values for each page side.
*
* @param {number} all The margin value for each side of the page.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* pageSettings.margins = new PdfMargins(40);
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(all: number);
/**
* Gets the left margin value of the page.
*
* @returns {number} Left margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Gets the left margin
* let left: number = pageSettings.margins.left;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the left margin value of the page.
*
* @param {number} value Left margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* let margins: PdfMargins = new PdfMargins();
* margins.left = 40;
* margins.right = 40;
* margins.top = 20;
* margins.bottom = 20;
* pageSettings.margins = margins;
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
left: number;
/**
* Gets the right margin value of the page.
*
* @returns {number} Right margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Gets the right margin
* let right: number = pageSettings.margins.right;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the right margin value of the page.
*
* @param {number} value - Right margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* let margins: PdfMargins = new PdfMargins();
* margins.left = 40;
* margins.right = 40;
* margins.top = 20;
* margins.bottom = 20;
* pageSettings.margins = margins;
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
right: number;
/**
* Gets the top margin value of the page.
*
* @returns {number} Top margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Gets the top margin
* let top: number = pageSettings.margins.top;
* // Destroy the document
* document.destroy();
* ```
*/
/**
*Sets the top margin value of the page.
*
* @param {number} value Top margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* let margins: PdfMargins = new PdfMargins();
* margins.left = 40;
* margins.right = 40;
* margins.top = 20;
* margins.bottom = 20;
* pageSettings.margins = margins;
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
top: number;
/**
* Get the bottom margin value of the page.
*
* @returns {number} Bottom margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Gets the bottom margin
* let bottom: number = pageSettings.margins.bottom;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the bottom margin value of the page.
*
* @param {number} value Bottom margin.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Create a new PDF page settings instance
* let pageSettings: PdfPageSettings = new PdfPageSettings();
* // Sets the margins
* let margins: PdfMargins = new PdfMargins();
* margins.left = 40;
* margins.right = 40;
* margins.top = 20;
* margins.bottom = 20;
* pageSettings.margins = margins;
* // Sets the page size
* pageSettings.size = {width: 595, height: 842};
* // Sets the page orientation
* pageSettings.orientation = PdfPageOrientation.landscape;
* // Add a new PDF page with page settings
* page = document.addPage(pageSettings);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
bottom: number;
}
/**
* Public class to provide data for the document split event, including the split index and PDF data.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* document.splitEvent = documentSplitEvent;
* // Split PDF document by fixed number of pages
* document.splitByFixedNumber(1);
* // Event to invoke while splitting PDF document data
* function documentSplitEvent(sender: PdfDocument, args: PdfDocumentSplitEventArgs): void {
* Save.save('output_' + args.splitIndex + '.pdf', new Blob([args.pdfData], { type: 'application/pdf' }));
* }
* // Destroy the document
* document.destroy();
*/
export declare class PdfDocumentSplitEventArgs {
private _index;
private _pdfData;
constructor(splitIndex: number, pdfData: Uint8Array);
readonly pdfData: Uint8Array;
readonly index: number;
}