@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
70 lines (69 loc) • 2.69 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 { PdfSingleValueField } from './single-value-field';
/**
* Represents an automatic field that displays the document's author.
*
* ```typescript
* // Create a new PDF document.
* const document: PdfDocument = new PdfDocument();
* // Create a new page.
* const page: PdfPage = document.addPage();
* // Set document information including author.
* const info: PdfDocumentInformation = { author: 'Syncfusion' };
* document.setDocumentInformation(info);
* // Initialize standard font.
* const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
* // Initialize solid brush.
* const brush: PdfBrush = new PdfBrush({r: 0, g: 0, b: 0});
* // Create the document author field.
* const authorField: PdfDocumentAuthorField = new PdfDocumentAuthorField({ font: font, brush: brush});
* // Draw the author field.
* authorField.draw(page.graphics, { x: 20, y: 30 });
* // Save the document.
* document.save('output.pdf');
* // Destroy the document.
* document.destroy();
* ```
*/
var PdfDocumentAuthorField = /** @class */ (function (_super) {
__extends(PdfDocumentAuthorField, _super);
function PdfDocumentAuthorField(properties) {
var _this = _super.call(this) || this;
if (properties) {
_this._initializeBase(properties.font, properties.brush, properties.stringFormat);
}
return _this;
}
/**
* Resolves document author metadata.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @returns {string} The document author.
*/
PdfDocumentAuthorField.prototype._getValue = function (graphics) {
var page = this._getPageFromGraphics(graphics);
if (page && page._crossReference && page._crossReference._document) {
var doc = page._crossReference._document;
var info = doc.getDocumentInformation();
if (info && info.author) {
return info.author;
}
}
return '';
};
return PdfDocumentAuthorField;
}(PdfSingleValueField));
export { PdfDocumentAuthorField };