@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
320 lines (319 loc) • 12 kB
TypeScript
import { _PdfDictionary } from './../pdf-primitives';
import { _PdfBaseStream } from './../base-stream';
import { PdfGraphics } from './pdf-graphics';
import { _PdfCrossReference } from './../pdf-cross-reference';
import { Rectangle, Size } from './../pdf-type';
/**
* `PdfTemplate` class represents the template of the PDF.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get the first page
* let page: PdfPage = document.getPage(0) as PdfPage;
* // Create a new rubber stamp annotation
* const annotation: PdfRubberStampAnnotation = new PdfRubberStampAnnotation({x: 50, y: 100, width: 100, height: 50});
* // Get the normal appearance of the annotation
* let normalAppearance: PdfTemplate = annotation.appearance.normal;
* // Create new image object by using JPEG image data as Base64 string format
* let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
* // Draw the image as the custom appearance for the annotation
* normalAppearance.graphics.drawImage(image, {x: 0, y: 0, width: 100, height: 50});
* // Add annotation to the page
* page.annotations.add(annotation);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfTemplate {
/**
* Internal structure storing template graphics and metadata.
*
* @private
*/
_content: any;
/**
* Size of the template in PDF units.
*
* @private
*/
_size: Size;
/**
* Indicates whether template transformations should be written.
*
* @private
*/
_writeTransformation: boolean;
/**
* Indicates whether the template is read only.
*
* @private
*/
_isReadOnly: boolean;
/**
* Indicates whether the template belongs to an annotation appearance.
*
* @private
*/
_isAnnotationTemplate: boolean;
/**
* Determines whether the template should be automatically scaled.
*
* @private
*/
_needScale: boolean;
/**
* Graphics instance used to draw within the template.
*
* @private
*/
_g: PdfGraphics;
/**
* Cross reference table associated with the template.
*
* @private
*/
_crossReference: _PdfCrossReference;
/**
* Indicates whether this template has already been exported.
*
* @private
*/
_isExported: boolean;
/**
* Indicates whether the template resources require export.
*
* @private
*/
_isResourceExport: boolean;
/**
* Raw appearance stream for annotation rendering.
*
* @private
*/
_appearance: string;
/**
* Pending resource dictionary entries for deferred export.
*
* @private
*/
_pendingResources: string;
/**
* Original size of the template prior to any scaling.
*
* @private
*/
_templateOriginalSize: Size;
/**
* Indicates that this template represents a digital signature appearance.
*
* @private
*/
_isSignature: boolean;
/**
* Indicates whether this template was newly created in the current session.
*
* @private
*/
_isNew: boolean;
/**
* Unique identifier for this template within resource dictionaries.
*
* @private
*/
_key: string;
/**
* Initializes a new instance of the `PdfTemplate` class.
*
* @private
*/
constructor();
/**
* Initializes a new instance of the `PdfTemplate` class.
*
* @param {_PdfBaseStream} appearance - The appearance stream.
* @param {_PdfCrossReference} crossReference - The cross reference object.
* @private
*/
constructor(appearance: _PdfBaseStream, crossReference: _PdfCrossReference);
/**
* Initializes a new instance of the `PdfTemplate` class.
*
* @param {number[]} bounds - The bounds.
* @param {_PdfCrossReference} crossReference - The cross reference object.
* @private
*/
constructor(bounds: number[], crossReference: _PdfCrossReference);
/**
* Initializes a new instance of the `PdfTemplate` class.
*
* @param {Size} size - The size of the template.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get the first page
* let page: PdfPage = document.getPage(0) as PdfPage;
* // Create a template
* const template: PdfTemplate = new PdfTemplate({ width: 400, height: 200 });
* // Create new image object by using JPEG image data as Base64 string format
* let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
* // Draw the image into the template graphics
* template.graphics.drawImage(image, {x: 0, y: 0, width: 100, height: 50});
* // Draw template to the page
* page.graphics.drawTemplate(template, {x: 0, y: 0, width: 100, height: 50});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(size: Size);
/**
* Initializes a new instance of the `PdfTemplate` class.
*
* @param {Rectangle} bounds - The bounding rectangle of the template.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get the first page
* let page: PdfPage = document.getPage(0) as PdfPage;
* // Create a template
* const template: PdfTemplate = new PdfTemplate({ x: 100, y: 100, width: 400, height: 200 });
* // Create new image object by using JPEG image data as Base64 string format
* let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
* // Draw the image into the template graphics
* template.graphics.drawImage(image, {x: 0, y: 0, width: 100, height: 50});
* // Draw template to the page
* page.graphics.drawTemplate(template, {x: 0, y: 0, width: 100, height: 50});
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(bounds: Rectangle);
constructor(bounds: Rectangle, crossReference: _PdfCrossReference);
/**
* Get the graphics of the PDF template. (Read only)
*
* @returns {PdfGraphics} The graphics object of the PDF template.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get the first page
* let page: PdfPage = document.getPage(0) as PdfPage;
* // Create a new rubber stamp annotation
* const annotation: PdfRubberStampAnnotation = new PdfRubberStampAnnotation({x: 50, y: 100, width: 100, height: 50});
* // Access the graphics of the normal appearance
* let graphics: PdfGraphics = annotation.appearance.normal.graphics;
* // Create new image object by using JPEG image data as Base64 string format
* let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
* // Draw the image as the custom appearance for the annotation
* graphics.drawImage(image, {x: 0, y: 0, width: 100, height: 50});
* // Add annotation to the page
* page.annotations.add(annotation);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly graphics: PdfGraphics;
/**
* Get the size of the PDF template. (Read only)
*
* @returns {Size} Template width and height as number array.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get the first page
* let page: PdfPage = document.getPage(0) as PdfPage;
* // Create a new rubber stamp annotation
* const annotation: PdfRubberStampAnnotation = new PdfRubberStampAnnotation({x: 50, y: 100, width: 100, height: 50});
* // Access the normal template of the appearance
* let template: PdfTemplate = appearance.normal;
* // Get the width and height of the PDF template as number array.
* let size: Size = template.size;
* // Create new image object by using JPEG image data as Base64 string format
* let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
* // Draw the image as the custom appearance for the annotation
* template.graphics.drawImage(image, {x: 0, y: 0, width: size.width, height: size.height});
* // Add annotation to the page
* page.annotations.add(annotation);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly size: Size;
/**
* Get the original size of the PDF template. (Read only)
*
* Remarks: The `_originalSize` property is internal and provides access to the original dimensions of the PDF template.
*
* @returns {Size} Template original width and height as number array.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Get the first page
* let page: PdfPage = document.getPage(0) as PdfPage;
* // Create a new rubber stamp annotation
* const annotation: PdfRubberStampAnnotation = new PdfRubberStampAnnotation({x: 50, y: 100, width: 100, height: 50});
* // Access the normal template of the appearance
* let template: PdfTemplate = appearance.normal;
* // Get the width and height of the PDF template as number array
* let size: Size = template._originalSize;
* // Create new image object by using JPEG image data as Base64 string format
* let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
* // Draw the image as the custom appearance for the annotation
* template.graphics.drawImage(image, {x: 0, y: 0, width: size.width, height: size.height});
* // Add annotation to the page
* page.annotations.add(annotation);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly _originalSize: Size;
/**
* Ensures the content dictionary is initialized as a Form XObject by setting.
*
* @private
* @returns {void}
*/
_initialize(): void;
/**
* Exports a dictionary entry to a compact JSON form suitable for
* appearance/resource serialization used by annotation appearance export.
*
* @private
* @param {_PdfDictionary} dictionary The container dictionary.
* @param {_PdfCrossReference} crossReference Cross reference context.
* @param {string} key The key to export.
* @returns {void}
*/
_exportStream(dictionary: _PdfDictionary, crossReference: _PdfCrossReference, key: string): void;
/**
* Imports a previously exported appearance/resource JSON into the template.
* When hasCrossReference is true, the parsed objects are wired to the current
* cross reference and flagged as updated.
*
* @private
* @param {boolean} hasCrossReference Whether to wire the parsed objects to the active xref.
* @param {boolean} [isResourceExport] When true, imports resources; otherwise imports stream.
* @returns {void}
*/
_importStream(hasCrossReference: boolean, isResourceExport?: boolean): void;
/**
* Resolves and writes any pending resource elements recorded in the templates
* content stream into the provided cross-reference, clearing the pending queue.
*
* @private
* @param {_PdfCrossReference} crossReference Cross reference to consume/write pending items.
* @returns {void}
*/
_updatePendingResource(crossReference: _PdfCrossReference): void;
}