UNPKG

@pdfme/pdf-lib

Version:

Create and modify PDF files with JavaScript

78 lines 2.68 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const PDFNumber_1 = __importDefault(require("../objects/PDFNumber")); const PDFString_1 = __importDefault(require("../objects/PDFString")); const PDFHexString_1 = __importDefault(require("../objects/PDFHexString")); const PDFName_1 = __importDefault(require("../objects/PDFName")); const PDFAcroTerminal_1 = __importDefault(require("./PDFAcroTerminal")); class PDFAcroText extends PDFAcroTerminal_1.default { MaxLen() { const maxLen = this.dict.lookup(PDFName_1.default.of('MaxLen')); if (maxLen instanceof PDFNumber_1.default) return maxLen; return undefined; } Q() { const q = this.dict.lookup(PDFName_1.default.of('Q')); if (q instanceof PDFNumber_1.default) return q; return undefined; } setMaxLength(maxLength) { this.dict.set(PDFName_1.default.of('MaxLen'), PDFNumber_1.default.of(maxLength)); } removeMaxLength() { this.dict.delete(PDFName_1.default.of('MaxLen')); } getMaxLength() { return this.MaxLen()?.asNumber(); } setQuadding(quadding) { this.dict.set(PDFName_1.default.of('Q'), PDFNumber_1.default.of(quadding)); } getQuadding() { return this.Q()?.asNumber(); } setValue(value) { this.dict.set(PDFName_1.default.of('V'), value); // const widgets = this.getWidgets(); // for (let idx = 0, len = widgets.length; idx < len; idx++) { // const widget = widgets[idx]; // const state = widget.getOnValue() === value ? value : PDFName.of('Off'); // widget.setAppearanceState(state); // } } removeValue() { this.dict.delete(PDFName_1.default.of('V')); } getValue() { const v = this.V(); if (v instanceof PDFString_1.default || v instanceof PDFHexString_1.default) return v; return undefined; } } Object.defineProperty(PDFAcroText, "fromDict", { enumerable: true, configurable: true, writable: true, value: (dict, ref) => new PDFAcroText(dict, ref) }); Object.defineProperty(PDFAcroText, "create", { enumerable: true, configurable: true, writable: true, value: (context) => { const dict = context.obj({ FT: 'Tx', Kids: [], }); const ref = context.register(dict); return new PDFAcroText(dict, ref); } }); exports.default = PDFAcroText; //# sourceMappingURL=PDFAcroText.js.map