UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

126 lines (125 loc) 5.09 kB
import { PdfTemplate } from './../graphics/pdf-template'; import { PdfAnnotation } from './annotation'; import { Rectangle } from './../pdf-type'; /** * `PdfAppearance` class represents the appearance of the annotation. * ```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 appearance of the annotation * let appearance: PdfAppearance = annotation.appearance; * // 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 * appearance.normal.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 PdfAppearance { /** * Holds the annotation associated with this appearance. * * @private */ _annotations: PdfAnnotation; /** * Defines the bounding rectangle of the appearance. * * @private */ _bounds: Rectangle; /** * Indicates whether the normal appearance key is used. * * @private */ _isNormalKey: boolean; private _crossReference; private _templateNormal; private _dictionary; /** * Initializes a new instance of the `PdfAppearance` class. * * @param {Rectangle} bounds - The bounds. * @param {PdfAnnotation} annot - The annotation. * @private */ constructor(bounds: Rectangle, annot?: PdfAnnotation); /** * Get the normal appearance of the annotation. * * @returns {PdfTemplate} Returns the normal appearance of the annotation. * ```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 appearance of the annotation * let appearance: PdfAppearance = annotation.appearance; * // Access the normal template of the appearance * let template: PdfTemplate = 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 * template.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(); * ``` */ /** * Set the normal appearance of the annotation. * * @param {PdfTemplate} value The normal appearance of the annotation. * ```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 appearance of the annotation * let appearance: PdfAppearance = annotation.appearance; * // Access the normal template of the appearance * let template: PdfTemplate = 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 * template.graphics.drawImage(image, {x: 0, y: 0, width: 100, height: 50}); * // Add annotation to the page * page.annotations.add(annotation); * // Add a new rubber stamp annotation to the page * const annotation2: PdfRubberStampAnnotation = new PdfRubberStampAnnotation({x: 50, y: 200, width: 100, height: 50}); * // Set the normal appearance of the annotation * annotation2.appearance.normal = annotation.appearance.normal; * // Add annotation to the page * page.annotations.add(annotation2); * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ normal: PdfTemplate; /** * Initializes the appearance template for the annotation using its bounds and cross reference. * * @private * @returns {void} nothing. */ _initialize(): void; }