@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
80 lines (79 loc) • 3.21 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 total number of pages in the current section.
*
* ```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 page count field.
* const sectionPageCountField: PdfSectionPageCountField = new PdfSectionPageCountField({ font: font, brush: brush });
* // Add page to the section.
* const page: PdfPage = section.addPage();
* // Draw the section page count field
* sectionPageCountField.draw(page.graphics, { x: 150, y: 10 });
* // Save the document.
* document.save('Output.pdf');
* // Destroy the document.
* document.destroy();
* ```
*/
var PdfSectionPageCountField = /** @class */ (function (_super) {
__extends(PdfSectionPageCountField, _super);
function PdfSectionPageCountField(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 total page count for the current section.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @returns {string} The formatted section page count.
*/
PdfSectionPageCountField.prototype._getValue = function (graphics) {
if (graphics) {
var page = this._getPageFromGraphics(graphics);
if (!page) {
return _formatNumber(1, this._numberStyle);
}
var sectionIndex = page._getSectionIndex();
if (sectionIndex < 0) {
return _formatNumber(1, this._numberStyle);
}
var document_1 = page._crossReference._document;
var section = document_1._sections[sectionIndex];
if (section) {
return _formatNumber(section._pageCount, this._numberStyle);
}
}
return _formatNumber(1, this._numberStyle);
};
return PdfSectionPageCountField;
}(PdfMultipleNumberValueField));
export { PdfSectionPageCountField };