UNPKG

@syncfusion/ej2-pdf

Version:

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

103 lines (102 loc) 4.45 kB
import { PdfTemplate } from './pdf-template'; /** * Represents a template element for creating and rendering header and footer content in a PDF document. * * ```typescript * // Create a new document * let document: PdfDocument = new PdfDocument(); * // Create a header template * let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({ width: 500, height: 50 }); * // Get the graphics of the template * let graphics: PdfGraphics = headerTemplate.graphics; * // Draw content on header * graphics.drawString('Document Header', font, {x: 10, y: 10, width: 550, height: 30}, brush); * // Assign to document * document.template.top = {template: headerTemplate, alignment: PdfTemplateHorizontalAlignment.center}; * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` */ var PdfPageTemplateElement = /** @class */ (function () { /** * Initializes a new instance of the page template element with the specified size. * * ```typescript * // Create a new document * let document: PdfDocument = new PdfDocument(); * // Create a header template with size * let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({width: 500, height: 50}); * // Draw content on header * headerTemplate.graphics.drawString('Header', font, {x: 10, y: 10, width: 550, height: 30}, brush); * // Assign to document * document.template.top = {template: headerTemplate, alignment: PdfTemplateHorizontalAlignment.center }; * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` * * @param {Size} size The size of the template element. */ function PdfPageTemplateElement(size) { this._bounds = { x: 0, y: 0, width: size.width, height: size.height }; } Object.defineProperty(PdfPageTemplateElement.prototype, "graphics", { /** * Gets the graphics surface to draw template content. * * ```typescript * // Create a new document * let document: PdfDocument = new PdfDocument(); * // Create a header template * let headerTemplate: PdfPageTemplateElement = new PdfPageTemplateElement({ width: 500, height: 50 }); * // Get the graphics of the template * let graphics: PdfGraphics = headerTemplate.graphics; * // Draw content on header * graphics.drawString('Document Header', font, {x: 10, y: 10, width: 550, height: 30}, brush); * // Assign to document * document.template.top = {template: headerTemplate, alignment: PdfTemplateHorizontalAlignment.center}; * // Save the document * document.save('output.pdf'); * // Destroy the document * document.destroy(); * ``` * * @returns {PdfGraphics} The graphics of the template. */ get: function () { if (!this._template) { this._template = new PdfTemplate(this._bounds, this._page ? this._page._crossReference : undefined); } return this._template.graphics; }, enumerable: true, configurable: true }); /** * Draws the template content onto the specified page graphics at the * This method renders the internal template, if available, onto the provided * Draws the template content onto the specified page graphics at the given position. * graphics context using the specified coordinates and dimensions. * * @private * @param {PdfGraphics} pageGraphics The page graphics context to draw onto. * @param {number} x The x-coordinate where the template should be drawn. * @param {number} y The y-coordinate where the template should be drawn. * @param {number} width The width to use when drawing the template. * @param {number} height The height to use when drawing the template. * @returns {void} This method does not return a value. */ PdfPageTemplateElement.prototype._draw = function (pageGraphics, x, y, width, height) { if (this._template) { pageGraphics.drawTemplate(this._template, { x: x, y: y, width: width, height: height }); } }; return PdfPageTemplateElement; }()); export { PdfPageTemplateElement };