UNPKG

@syncfusion/ej2-pdf

Version:

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

99 lines (98 loc) 4.04 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { PdfTemplate } from '../pdf-template'; import { PdfAutomaticField } from './automatic-field'; /** * Represents an abstract class for static field. * * ```typescript * // Create a new document. * const document: PdfDocument = new PdfDocument(); * // Add new page to document. * const page: PdfPage = document.addPage(); * // Initialize standard font. * const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12); * // Initialize solid brush. * const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 }); * // Create a static date-time field. * const dateField: PdfStaticField = new PdfDateTimeField({ font: font, brush: brush }); * // Render the static field inside the template. * dateField.draw(page.graphics, { x: 20, y: 20 }); * // Save the document. * document.save('Output.pdf'); * // Destroy the document. * document.destroy(); * ``` */ var PdfStaticField = /** @class */ (function (_super) { __extends(PdfStaticField, _super); function PdfStaticField() { var _this = _super !== null && _super.apply(this, arguments) || this; /** * Indicates whether the field has already been rendered. * * @private */ _this._hasRendered = false; return _this; } /** * Initializes the base static field with optional font, brush, and string format settings. * * @private * @param {PdfFont} [font] - The font used for rendering the field text. * @param {PdfBrush} [brush] - The brush used to define the text color. * @param {PdfStringFormat} [stringFormat] - The format used for text layout and alignment. * @returns {void} Does not return a value */ PdfStaticField.prototype._initializeBase = function (font, brush, stringFormat) { _super.prototype._initializeBase.call(this, font, brush, stringFormat); }; /** * Performs static field rendering with global caching. * * @private * @param {PdfGraphics} graphics The graphics context. * @param {Point} location The drawing location. * @returns {void} Nothing. */ PdfStaticField.prototype._performDraw = function (graphics, location) { _super.prototype._performDraw.call(this, graphics, location); if (!this._template) { var value = this._getValue(graphics); var font = this._obtainFont(); var brush = this._obtainBrush(); var size_1 = this._obtainSize(); var template = new PdfTemplate({ x: 0, y: 0, width: size_1.width, height: size_1.height }); template.graphics.drawString(value, font, { x: 0, y: 0, width: size_1.width, height: size_1.height }, brush); this._template = template; } var size = this._obtainSize(); var bounds = { x: location.x, y: location.y, width: size.width, height: size.height }; graphics.drawTemplate(this._template, bounds); }; /** * Returns the string representation of the field’s value used during rendering. * * @private * @param {PdfGraphics} graphics The graphics context used for rendering. * @returns {string} The formatted value to be rendered. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars PdfStaticField.prototype._getValue = function (graphics) { return ''; }; return PdfStaticField; }(PdfAutomaticField)); export { PdfStaticField };