UNPKG

@syncfusion/ej2-pdf

Version:

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

72 lines (71 loc) 2.86 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 { _formatNumber } from '../../utils'; import { PdfMultipleNumberValueField } from './multiple-number-value-field'; /** * Represents an automatic field that provides the section number for the current page within the document. * * ```typescript * // Create a new document. * const document: PdfDocument = new PdfDocument(); * // Add sections to the document. * const section: PdfSection = document.addSection(); * // Initialize standard font. * const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 13); * // Initialize brush. * const brush: PdfBrush = new PdfBrush({ r: 255, g: 0, b: 255 }); * // Create a section number field. * const sectionNumberField: PdfSectionNumberField = new PdfSectionNumberField({ font: font, brush: brush }); * // Add page to the section. * const page: PdfPage = section.addPage(); * // Draw the section number * sectionNumberField.draw(page.graphics, { x: 150, y: 10 }); * // Save the document. * document.save('Output.pdf'); * // Destroy the document. * document.destroy(); * ``` */ var PdfSectionNumberField = /** @class */ (function (_super) { __extends(PdfSectionNumberField, _super); function PdfSectionNumberField(properties) { var _this = _super.call(this) || this; if (properties) { _this._initializeBase(properties.font, properties.brush, properties.stringFormat); if (properties.numberStyle) { _this._numberStyle = properties.numberStyle; } } return _this; } /** * Resolves section number for the current page. * * @private * @param {PdfGraphics} graphics The graphics context. * @returns {string} The formatted section number. */ PdfSectionNumberField.prototype._getValue = function (graphics) { var page = this._getPageFromGraphics(graphics); if (page && page._pageDictionary) { var sectionIndex = page._getSectionIndex(); if (sectionIndex >= 0) { return _formatNumber(sectionIndex + 1, this._numberStyle); } } return _formatNumber(1, this._numberStyle); }; return PdfSectionNumberField; }(PdfMultipleNumberValueField)); export { PdfSectionNumberField };