@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
156 lines (155 loc) • 6.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 { PdfXmpSchema } from './pdf-xmp-schema';
import { PdfXmpSchemaType } from '../enumerator';
/**
* Represents a user-defined metadata schema with custom properties.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access the document properties
* let documentProperties: PdfDocumentInformation = document.getDocumentInformation(false);
* // Gets XMP metadata
* let xmpMetadata: PdfXmpMetadata = documentProperties.xmpMetadata;
* // Create a custom schema
* let custom: PdfCustomSchema = new PdfCustomSchema(xmpMetadata, 'cust', 'http://custom.example.com/ns/');
* custom.customData.set('appVersion', '1.0.0');
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
var PdfCustomSchema = /** @class */ (function (_super) {
__extends(PdfCustomSchema, _super);
/**
* Initializes a new `PdfCustomSchema` instance.
*
* @param {PdfXmpMetadata} xmp Parent PdfXmpMetadata reference.
* @param {string} namespacePrefix The XML namespace prefix.
* @param {string} namespaceUri The namespace URI.
*/
function PdfCustomSchema(xmp, namespacePrefix, namespaceUri) {
var _this = _super.call(this, xmp) || this;
_this._namespace = namespacePrefix;
_this._namespaceUri = namespaceUri;
_this._customNamespaceUri = namespaceUri;
_this._prefix = namespacePrefix;
_this._name = namespaceUri;
_this._customdata = new Map();
if (_this._xmp) {
_this._xmp._customSchemas.push(_this);
}
return _this;
}
Object.defineProperty(PdfCustomSchema.prototype, "schemaType", {
/**
* Gets the schema type.
*
* @returns {PdfXmpSchemaType} The schema type.
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access the document properties
* let documentProperties: PdfDocumentInformation = document.getDocumentInformation(false);
* // Create a custom schema
* let custom: PdfCustomSchema = new PdfCustomSchema(documentProperties.xmpMetadata, 'cust', 'http://custom.example.com/ns/');
* let schemaType: PdfXmpSchemaType = custom.schemaType;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
get: function () {
return PdfXmpSchemaType.custom;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PdfCustomSchema.prototype, "customData", {
/**
* Gets the custom data map.
*
* @returns {Map<string, string>} The custom data.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access the document properties
* let documentProperties: PdfDocumentInformation = document.getDocumentInformation(false);
* // Gets XMP metadata
* let xmpMetadata: PdfXmpMetadata = documentProperties.xmpMetadata;
* // Create a custom schema
* let custom: PdfCustomSchema = new PdfCustomSchema(documentProperties.xmpMetadata, 'cust', 'http://custom.example.com/ns/');
* // Gets the customData values
* let customData: Map<string, string> = customSchema.customData;
* // Destroy the document
* document.destroy();
* ```
*/
get: function () {
return this._customdata;
},
/**
* Sets the custom data map.
*
* @param {Map<string, string>} value The custom data to set.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data, password);
* // Access the document properties
* let documentProperties: PdfDocumentInformation = document.getDocumentInformation(false);
* // Gets XMP metadata
* let xmpMetadata: PdfXmpMetadata = documentProperties.xmpMetadata;
* // Create a custom schema
* let custom: PdfCustomSchema = new PdfCustomSchema(documentProperties.xmpMetadata, 'cust', 'http://custom.example.com/ns/');
* // Sets custom data map
* let dataMap: Map<string, string> = new Map<string, string>();
* dataMap.set('appVersion', '1.0.0');
* dataMap.set('buildNumber', '12345');
* custom.customData = dataMap;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
set: function (value) {
this._customdata = value;
},
enumerable: true,
configurable: true
});
/**
* Serializes custom data entries to RDF/XML using the provided writer.
* Skips serialization when customData is empty.
*
* @private
* @param {_XmlWriter} writer The XML writer to serialize into.
* @returns {void}
*/
PdfCustomSchema.prototype._writeXml = function (writer) {
var _this = this;
if (this._customdata.size === 0) {
return;
}
this._customdata.forEach(function (value, key) {
writer._writeElementString(key, value, _this._namespace, _this._namespaceUri);
});
};
return PdfCustomSchema;
}(PdfXmpSchema));
export { PdfCustomSchema };