UNPKG

@syncfusion/ej2-pdf

Version:

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

132 lines (131 loc) 5.69 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 { PdfPageNumberField } from './page-number-field'; /** * Represents an automatic field that shows the page number of a specified destination page within the document. * * ```typescript * // Create a new document. * const document: PdfDocument = new PdfDocument(); * // Initialize standard font. * const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 13); * // Initialize brush. * const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 }); * // Create a destination page number field with the specified properties. * const destinationPageField: PdfDestinationPageNumberField = new PdfDestinationPageNumberField({ font: font, brush: brush }); * // Add pages and set the destination to the final page and draw the field there. * for (let i = 0; i < 5; i++) { * const page: PdfPage = document.addPage(); * if (i === 4) { * destinationPageField.page = page; * destinationPageField.draw(page.graphics, { x: 10, y: 10 }); * } * } * // Save the document. * document.save('output.pdf'); * // Destroy the document. * document.destroy(); * ``` */ var PdfDestinationPageNumberField = /** @class */ (function (_super) { __extends(PdfDestinationPageNumberField, _super); function PdfDestinationPageNumberField(properties) { var _this = _super.call(this, properties) || this; if (properties && properties.page) { _this._page = properties.page; } return _this; } Object.defineProperty(PdfDestinationPageNumberField.prototype, "page", { /** * Gets the currently assigned destination page. * * ```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, 13); * // Initialize brush. * const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 }); * // Initialize a string format. * const format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right); * // Create a destination page number field with the specified properties. * const destinationPageField: PdfDestinationPageNumberField = new PdfDestinationPageNumberField({font: font, brush: brush, stringFormat: format, numberStyle: PdfNumberStyle.numeric, page: page}); * // Get the assigned destination page * const destinationPage: PdfPage = destinationPageField.page; * // Draw the destination page field. * destinationPageField.draw(page.graphics, { x: 10, y: 10 }); * // Save the document. * document.save('output.pdf'); * // Destroy the document. * document.destroy(); * ``` * * @returns {PdfPage} The destination page. */ get: function () { return this._page; }, /** * Sets the destination page of the field. * * // 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, 13); * // Initialize brush. * const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 }); * // Initialize a string format. * const format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right); * // Create a destination page number field with the specified properties. * const destinationPageField: PdfDestinationPageNumberField = new PdfDestinationPageNumberField({font: font, brush: brush, stringFormat: format, numberStyle: PdfNumberStyle.numeric}); * // Set destination and draw on the destination page. * destinationPageField.page = page; * // Draw the destination page field. * destinationPageField.draw(page.graphics, { x: 10, y: 10 }); * // Save the document. * document.save('output.pdf'); * // Destroy the document. * document.destroy(); * ``` * * @param {PdfPage} value The destination page. */ set: function (value) { this._page = value; }, enumerable: true, configurable: true }); /** * Resolves destination page number. * * @private * @param {PdfGraphics} graphics The graphics context. * @returns {string} The formatted page number. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars PdfDestinationPageNumberField.prototype._getValue = function (graphics) { if (this._page) { return this._internalLoadedGetValue(this._page); } return '1'; }; return PdfDestinationPageNumberField; }(PdfPageNumberField)); export { PdfDestinationPageNumberField };