@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
85 lines (84 loc) • 3.14 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 { _padStart } from '../../utils';
import { PdfStaticField } from './static-field';
/**
* Represents an automatic field that displays the current date and time at the time of creation.
*
* ```typescript
* // Create a new document.
* const document: PdfDocument = new PdfDocument();
* // Add pages to the 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 the date-time field.
* const dateTimeField: PdfDateTimeField = new PdfDateTimeField({ font: font, brush: brush });
* // Draw the date-time field on page.
* dateTimeField.draw(page.graphics, { x: 10, y: 10 });
* // Save the document.
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
var PdfDateTimeField = /** @class */ (function (_super) {
__extends(PdfDateTimeField, _super);
function PdfDateTimeField(properties) {
var _this = _super.call(this) || this;
/**
* Gets or sets the format string used to display the creation date.
*
* @private
*/
_this._formatString = 'yyyy/MM/dd';
if (properties) {
_this._initializeBase(properties.font, properties.brush, properties.stringFormat);
}
_this._date = new Date();
return _this;
}
/**
* Resolves formatted date/time value.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @returns {string} The formatted date/time.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
PdfDateTimeField.prototype._getValue = function (graphics) {
return this._formatDate(this._date, this._formatString);
};
/**
* Formats a date according to the format string.
*
* @private
* @param {Date} date The date to format.
* @param {string} format The format string.
* @returns {string} The formatted date.
*/
PdfDateTimeField.prototype._formatDate = function (date, format) {
var year = date.getFullYear();
var month = _padStart(String(date.getMonth() + 1), 2, '0');
var day = _padStart(String(date.getDate()), 2, '0');
return format
.replace('yyyy', String(year))
.replace('MM', month)
.replace('dd', day);
};
return PdfDateTimeField;
}(PdfStaticField));
export { PdfDateTimeField };