@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
132 lines (131 loc) • 5.22 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 { PdfNumberStyle } from '../../enumerator';
import { _formatNumber } from '../../utils';
import { PdfSingleValueField } from './single-value-field';
/**
* Represents an automatic field that displays the total number of pages in the document.
*
* ```typescript
* // Create a new document.
* const document: PdfDocument = new PdfDocument();
* // Add page to the document.
* const page: PdfPage = document.addPage();
* // Initialize the standard font.
* const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 13);
* // Initialize solid brush.
* const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
* // Create the page count field.
* const pageCountField: PdfPageCountField = new PdfPageCountField({ font: font, brush: brush });
* // Draw the page count on page.
* pageCountField.draw(page.graphics, { x: 10, y: 10 });
* // Save the document.
* document.save('Output.pdf');
* // Destroy the document.
* document.destroy();
* ```
*/
var PdfPageCountField = /** @class */ (function (_super) {
__extends(PdfPageCountField, _super);
function PdfPageCountField(properties) {
var _this = _super.call(this) || this;
/**
* Specifies the number style used for formatting the field value.
*
* @private
*/
_this._numberStyle = PdfNumberStyle.numeric;
if (properties) {
_this._initializeBase(properties.font, properties.brush, properties.stringFormat);
if (properties.numberStyle) {
_this._numberStyle = properties.numberStyle;
}
}
return _this;
}
Object.defineProperty(PdfPageCountField.prototype, "numberStyle", {
/**
* Gets the number formatting style currently used to render the page count.
*
* ```typescript
* // Create a new document.
* const document: PdfDocument = new PdfDocument();
* // Add page to the document.
* const page: PdfPage = document.addPage();
* // Create the page count field.
* const pageCountField: PdfPageCountField = new PdfPageCountField({numberStyle: PdfNumberStyle.lowerLatin});
* // Get the number formatting style currently used to render the page count.
* const style: PdfNumberStyle = pageCountField.numberStyle;
* // Draw the page count on page.
* pageCountField.draw(page.graphics, { x: 10, y: 10 });
* // Save the document.
* document.save('Output.pdf');
* // Destroy the document.
* document.destroy();
* ```
*
* @returns {PdfNumberStyle} The current number formatting style.
*/
get: function () {
return this._numberStyle;
},
/**
* Sets the number formatting style used to render the page count.
*
* ```typescript
* // Create a new document.
* const document: PdfDocument = new PdfDocument();
* // Add page to the document.
* const page: PdfPage = document.addPage();
* // Create the page count field.
* const pageCountField: PdfPageCountField = new PdfPageCountField({numberStyle: PdfNumberStyle.lowerLatin});
* // Set the number formatting style used to render the page count.
* pageCountField.numberStyle = PdfNumberStyle.lowerLatin;
* // Draw the page count on page.
* pageCountField.draw(page.graphics, { x: 10, y: 10 });
* // Save the document.
* document.save('Output.pdf');
* // Destroy the document.
* document.destroy();
* ```
*
* @param {PdfNumberStyle} value The number formatting style to apply.
*/
set: function (value) {
this._numberStyle = value;
},
enumerable: true,
configurable: true
});
/**
* Resolves total page count.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @returns {string} The formatted page count.
*/
PdfPageCountField.prototype._getValue = function (graphics) {
if (graphics) {
var page = this._getPageFromGraphics(graphics);
if (page && page._crossReference && page._crossReference._document) {
var doc = page._crossReference._document;
var pageCount = doc.pageCount;
return _formatNumber(pageCount, this._numberStyle);
}
}
return '1';
};
return PdfPageCountField;
}(PdfSingleValueField));
export { PdfPageCountField };