UNPKG

@syncfusion/ej2-pdf

Version:

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

81 lines (80 loc) 3.1 kB
import { _packBits } from './utils'; /** * Represents an internal structure used to describe external PDF data, * including object references, descriptors, and encoded content. * * @private */ var _PdfExternal = /** @class */ (function () { function _PdfExternal(directReference, indirectReference, dataValueDescriptor, encoding) { if (encoding && directReference && dataValueDescriptor && indirectReference) { this._directReference = directReference; this._indirectReference = indirectReference; this._dataValueDescriptor = dataValueDescriptor; this._encoding = encoding; } else { throw new Error('Invalid constructor arguments'); } } /** * Converts the internal external value into a human readable string representation. * * @private * @returns {string} A formatted textual representation of the external data value. */ _PdfExternal.prototype._toString = function () { var result = 'EXTERNAL { '; if (this._directReference) { result += "directReference " + this._directReference.toString() + " "; } if (this._indirectReference) { result += "indirectReference " + this._indirectReference.toString() + " "; } if (this._dataValueDescriptor) { result += "dataValueDescriptor '" + this._dataValueDescriptor + "' "; } if (this._encoding instanceof Uint8Array) { result += "octet-aligned " + Array.from(this._encoding).map(function (byte) { return byte.toString(16); }).join('') + " "; } else if (this._encoding instanceof Uint8ClampedArray) { result += "arbitrary " + this._encoding.toString() + " "; } else { result += "single-ASN1-type " + this._encoding.toString() + " "; } result += '}'; return result; }; /** * Converts the internal external value into a JSON compatible representation. * * @private * @returns {any} A JSON object containing the external value s references, descriptor, * and encoded data. */ _PdfExternal.prototype._toJson = function () { var encoding; // eslint-disable-line if (this._encoding instanceof Uint8Array) { encoding = Array.from(this._encoding) .map(function (byte) { return byte.toString(16); }) .join(''); } else if (this._encoding instanceof Uint8ClampedArray) { var bits = this._encoding; encoding = { length: bits.length, value: Array.from(_packBits(bits)) .map(function (byte) { return byte.toString(16); }) .join('') }; } return { directReference: this._directReference, indirectReference: this._indirectReference, dataValueDescriptor: this._dataValueDescriptor, encoding: encoding }; }; return _PdfExternal; }()); export { _PdfExternal };