UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

144 lines (143 loc) 5.44 kB
/** * Represents the custom metadata for a PDF document. * Provides methods to manage key-value metadata pairs. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Access the document properties * let documentProperties: PdfDocumentProperites = document.getDocumentInformation(false); * // Gets the custom metadata * let custom: PdfCustomMetadata = documentProperties.customMetadata; * // Sets custom value * custom.set('key','value'); * // Sets the document Information * document.setDocumentInformation(documentProperties); * // Saves the document * document.save(); * ``` */ var PdfCustomMetadata = /** @class */ (function () { function PdfCustomMetadata() { /** * Stores custom metadata properties. * * @private * */ this._customData = new Map(); this._standardKeys = new Set(['title', 'author', 'subject', 'keywords', 'creator', 'producer', 'language', 'creationDate', 'modificationDate']); } /** * Sets a key to the custom data map. * * @param {string} key The metadata key. * @param {string} value The metadata value. * @returns {void} Nothing * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Access the document informations * let documentProperties: PdfDocumentProperites = document.getDocumentInformation(false); * // Gets the custom metadata from document information * let custom: PdfCustomMetadata= documentProperties.customMetadata; * // Sets a custom metadata value * custom.set('key','value'); * // Sets the document Information * document.setDocumentInformation(documentProperties); * // Saves the document * document.save(); * ``` */ PdfCustomMetadata.prototype.set = function (key, value) { if (typeof key === 'undefined' || key === null || typeof value === 'undefined' || value === null) { throw new Error('Key and value should not be null'); } if (key === '' || value === '') { throw new Error('Key and value should not be empty'); } if (this._standardKeys.has(key.toLowerCase())) { throw new Error('The Custom key cannot be a standard property'); } this._customData.set(key, value); }; /** * Gets a key from the custom data map. * * @param {string} key The key to get. * @returns {string} value The value of the key. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Access the document informations * let documentProperties: PdfDocumentProperites = document.getDocumentInformation(false); * // Gets the custom metadata from document information * let custom:PdfCustomMetadata = documentProperties.customMetadata; * // Gets a custom metadata value * let value: string = custom.get('key'); * // Saves the document * document.save(); * ``` */ PdfCustomMetadata.prototype.get = function (key) { if (typeof key === 'undefined' || key === null) { throw new Error('Key value should not be null'); } return this._customData.get(key); }; /** * Checks whether a key exists in the custom data map. * * @param {string} key The key to check. * @returns {boolean} True if the key exists; otherwise false. * * ```typescript * // Load an existing PDF document * let document: PdfDocument = new PdfDocument(data, password); * // Access the document informations * let documentProperties: PdfDocumentProperites = document.getDocumentInformation(false); * // Gets the custom metadata from document information * let custom:PdfCustomMetadata = documentProperties.customMetadata; * // Check the key is present in the custom metadata * let exists: boolean = custom.has('key'); * // Saves the document * document.save(); * ``` */ PdfCustomMetadata.prototype.has = function (key) { if (typeof key === 'undefined' || key === null) { throw new Error('Key value should not be null'); } return this._customData.has(key); }; /** * Removes a key from the custom data map. * * @param {string} key The key to remove. * @returns {void} Nothing. * * ```typescript * // Load an existing PDF document * // Access the document informations * let documentProperties: PdfDocumentProperites = document.getDocumentInformation(false); * // Gets the custom metadata from document information * let custom:PdfCustomMetadata = documentProperties.customMetadata; * // Removes the key from the custom metadata * custom.remove('key'); * // Sets the document Information * document.setDocumentInformation(documentProperties); * // Saves the document * document.save(); * ``` */ PdfCustomMetadata.prototype.remove = function (key) { if (typeof key === 'undefined' || key === null) { throw new Error('Key value should not be null'); } this._customData.delete(key); }; return PdfCustomMetadata; }()); export { PdfCustomMetadata };