@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
84 lines (83 loc) • 3.13 kB
JavaScript
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 displays the current page number.
*
* ```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 brush.
* const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
* // Create a page-number field.
* const pageNumberField: PdfPageNumberField = new PdfPageNumberField({ font: font, brush: brush });
* // Use numeric formatting for the page number.
* pageNumberField.numberStyle = PdfNumberStyle.numeric;
* // Draw page number field on page graphics.
* pageNumberField.draw(page.graphics, { x: 250, y: 750 });
* // Save the document.
* document.save('Output.pdf');
* // Destroy the document.
* document.destroy();
* ```
*/
var PdfPageNumberField = /** @class */ (function (_super) {
__extends(PdfPageNumberField, _super);
function PdfPageNumberField(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;
}
/**
* Gets the current page number.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @returns {string} The formatted page number.
*/
PdfPageNumberField.prototype._getValue = function (graphics) {
if (graphics) {
var page = this._getPageFromGraphics(graphics);
if (page && page._crossReference && page._crossReference._document) {
return _formatNumber(page._pageIndex + 1, this._numberStyle);
}
}
return '1';
};
/**
* Gets page number for loaded documents.
*
* @private
* @param {any} page The loaded page.
* @returns {string} The formatted page number.
*/
PdfPageNumberField.prototype._internalLoadedGetValue = function (page) {
if (page) {
return _formatNumber(page._pageIndex + 1, this._numberStyle);
}
return '1';
};
return PdfPageNumberField;
}(PdfMultipleNumberValueField));
export { PdfPageNumberField };