UNPKG

pdf-lib

Version:

Library for creating and modifying PDF files in JavaScript

51 lines (50 loc) 2.63 kB
var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import isNumber from 'lodash/isNumber'; import { addStringToBuffer } from '../../utils'; import { isIdentity, validate } from '../../utils/validate'; import PDFObject from './PDFObject'; // const pdfIndirectRefEnforcer = Symbol('PDF_INDIRECT_REF_ENFORCER'); // Using a Symbol is ideal here, but React Native doesn't current support them, // so we'll use a string instead. var pdfIndirectRefEnforcer = '@@__PDF_INDIRECT_REF_ENFORCER'; var pdfIndirectRefPool = new Map(); // TODO: Need to error out if obj or gen numbers are manually set! // tslint:disable-next-line:no-unused-variable var PDFIndirectReference = /** @class */ (function (_super) { __extends(PDFIndirectReference, _super); function PDFIndirectReference(enforcer, objectNumber, generationNumber) { var _this = _super.call(this) || this; _this.clone = function () { return _this; }; _this.toString = function () { return _this.objectNumber + " " + _this.generationNumber + " R"; }; _this.bytesSize = function () { return _this.toString().length; }; _this.copyBytesInto = function (buffer) { return addStringToBuffer(_this.toString(), buffer); }; validate(enforcer, isIdentity(pdfIndirectRefEnforcer), 'Cannot create PDFIndirectReference via constructor. Use PDFIndirectReference.forNumbers instead.'); validate(objectNumber, isNumber, 'objectNumber must be a Number'); validate(generationNumber, isNumber, 'generationNumber must be a Number'); _this.objectNumber = objectNumber; _this.generationNumber = generationNumber; return _this; } PDFIndirectReference.forNumbers = function (objectNumber, generationNumber) { var key = objectNumber + " " + generationNumber; var indirectRef = pdfIndirectRefPool.get(key); if (!indirectRef) { indirectRef = new PDFIndirectReference(pdfIndirectRefEnforcer, objectNumber, generationNumber); pdfIndirectRefPool.set(key, indirectRef); } return indirectRef; }; return PDFIndirectReference; }(PDFObject)); export default PDFIndirectReference;