UNPKG

survey-pdf

Version:

survey.pdf.js is a SurveyJS PDF Library. It is a easy way to export SurveyJS surveys to PDF. It uses JSON for survey metadata.

1,306 lines (1,265 loc) 599 kB
/*! * surveyjs - SurveyJS PDF library v2.0.5 * Copyright (c) 2015-2025 Devsoft Baltic OÜ - http://surveyjs.io/ * License: MIT (http://www.opensource.org/licenses/mit-license.php) */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("survey-core"), require("jspdf")); else if(typeof define === 'function' && define.amd) define("SurveyPDF", ["survey-core", "jspdf"], factory); else if(typeof exports === 'object') exports["SurveyPDF"] = factory(require("survey-core"), require("jspdf")); else root["SurveyPDF"] = factory(root["Survey"], root["jspdf"]); })(this, (__WEBPACK_EXTERNAL_MODULE_survey_core__, __WEBPACK_EXTERNAL_MODULE_jspdf__) => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./node_modules/node-interval-tree/lib/index.js": /*!******************************************************!*\ !*** ./node_modules/node-interval-tree/lib/index.js ***! \******************************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; // An augmented AVL Tree where each node maintains a list of records and their search intervals. // Record is composed of an interval and its underlying data, sent by a client. This allows the // interval tree to have the same interval inserted multiple times, as long its data is different. // Both insertion and deletion require O(log n) time. Searching requires O(k*logn) time, where `k` // is the number of intervals in the output list. Object.defineProperty(exports, "__esModule", ({ value: true })); var isSame = __webpack_require__(/*! shallowequal */ "./node_modules/shallowequal/index.js"); function height(node) { if (node === undefined) { return -1; } else { return node.height; } } var Node = /** @class */ (function () { function Node(intervalTree, record) { this.intervalTree = intervalTree; this.records = []; this.height = 0; this.key = record.low; this.max = record.high; // Save the array of all records with the same key for this node this.records.push(record); } // Gets the highest record.high value for this node Node.prototype.getNodeHigh = function () { var high = this.records[0].high; for (var i = 1; i < this.records.length; i++) { if (this.records[i].high > high) { high = this.records[i].high; } } return high; }; // Updates height value of the node. Called during insertion, rebalance, removal Node.prototype.updateHeight = function () { this.height = Math.max(height(this.left), height(this.right)) + 1; }; // Updates the max value of all the parents after inserting into already existing node, as well as // removing the node completely or removing the record of an already existing node. Starts with // the parent of an affected node and bubbles up to root Node.prototype.updateMaxOfParents = function () { if (this === undefined) { return; } var thisHigh = this.getNodeHigh(); if (this.left !== undefined && this.right !== undefined) { this.max = Math.max(Math.max(this.left.max, this.right.max), thisHigh); } else if (this.left !== undefined && this.right === undefined) { this.max = Math.max(this.left.max, thisHigh); } else if (this.left === undefined && this.right !== undefined) { this.max = Math.max(this.right.max, thisHigh); } else { this.max = thisHigh; } if (this.parent) { this.parent.updateMaxOfParents(); } }; /* Left-Left case: z y / \ / \ y T4 Right Rotate (z) x z / \ - - - - - - - - -> / \ / \ x T3 T1 T2 T3 T4 / \ T1 T2 Left-Right case: z z x / \ / \ / \ y T4 Left Rotate (y) x T4 Right Rotate(z) y z / \ - - - - - - - - -> / \ - - - - - - - -> / \ / \ T1 x y T3 T1 T2 T3 T4 / \ / \ T2 T3 T1 T2 */ // Handles Left-Left case and Left-Right case after rebalancing AVL tree Node.prototype._updateMaxAfterRightRotate = function () { var parent = this.parent; var left = parent.left; // Update max of left sibling (x in first case, y in second) var thisParentLeftHigh = left.getNodeHigh(); if (left.left === undefined && left.right !== undefined) { left.max = Math.max(thisParentLeftHigh, left.right.max); } else if (left.left !== undefined && left.right === undefined) { left.max = Math.max(thisParentLeftHigh, left.left.max); } else if (left.left === undefined && left.right === undefined) { left.max = thisParentLeftHigh; } else { left.max = Math.max(Math.max(left.left.max, left.right.max), thisParentLeftHigh); } // Update max of itself (z) var thisHigh = this.getNodeHigh(); if (this.left === undefined && this.right !== undefined) { this.max = Math.max(thisHigh, this.right.max); } else if (this.left !== undefined && this.right === undefined) { this.max = Math.max(thisHigh, this.left.max); } else if (this.left === undefined && this.right === undefined) { this.max = thisHigh; } else { this.max = Math.max(Math.max(this.left.max, this.right.max), thisHigh); } // Update max of parent (y in first case, x in second) parent.max = Math.max(Math.max(parent.left.max, parent.right.max), parent.getNodeHigh()); }; /* Right-Right case: z y / \ / \ T1 y Left Rotate(z) z x / \ - - - - - - - -> / \ / \ T2 x T1 T2 T3 T4 / \ T3 T4 Right-Left case: z z x / \ / \ / \ T1 y Right Rotate (y) T1 x Left Rotate(z) z y / \ - - - - - - - - -> / \ - - - - - - - -> / \ / \ x T4 T2 y T1 T2 T3 T4 / \ / \ T2 T3 T3 T4 */ // Handles Right-Right case and Right-Left case in rebalancing AVL tree Node.prototype._updateMaxAfterLeftRotate = function () { var parent = this.parent; var right = parent.right; // Update max of right sibling (x in first case, y in second) var thisParentRightHigh = right.getNodeHigh(); if (right.left === undefined && right.right !== undefined) { right.max = Math.max(thisParentRightHigh, right.right.max); } else if (right.left !== undefined && right.right === undefined) { right.max = Math.max(thisParentRightHigh, right.left.max); } else if (right.left === undefined && right.right === undefined) { right.max = thisParentRightHigh; } else { right.max = Math.max(Math.max(right.left.max, right.right.max), thisParentRightHigh); } // Update max of itself (z) var thisHigh = this.getNodeHigh(); if (this.left === undefined && this.right !== undefined) { this.max = Math.max(thisHigh, this.right.max); } else if (this.left !== undefined && this.right === undefined) { this.max = Math.max(thisHigh, this.left.max); } else if (this.left === undefined && this.right === undefined) { this.max = thisHigh; } else { this.max = Math.max(Math.max(this.left.max, this.right.max), thisHigh); } // Update max of parent (y in first case, x in second) parent.max = Math.max(Math.max(parent.left.max, right.max), parent.getNodeHigh()); }; Node.prototype._leftRotate = function () { var rightChild = this.right; rightChild.parent = this.parent; if (rightChild.parent === undefined) { this.intervalTree.root = rightChild; } else { if (rightChild.parent.left === this) { rightChild.parent.left = rightChild; } else if (rightChild.parent.right === this) { rightChild.parent.right = rightChild; } } this.right = rightChild.left; if (this.right !== undefined) { this.right.parent = this; } rightChild.left = this; this.parent = rightChild; this.updateHeight(); rightChild.updateHeight(); }; Node.prototype._rightRotate = function () { var leftChild = this.left; leftChild.parent = this.parent; if (leftChild.parent === undefined) { this.intervalTree.root = leftChild; } else { if (leftChild.parent.left === this) { leftChild.parent.left = leftChild; } else if (leftChild.parent.right === this) { leftChild.parent.right = leftChild; } } this.left = leftChild.right; if (this.left !== undefined) { this.left.parent = this; } leftChild.right = this; this.parent = leftChild; this.updateHeight(); leftChild.updateHeight(); }; // Rebalances the tree if the height value between two nodes of the same parent is greater than // two. There are 4 cases that can happen which are outlined in the graphics above Node.prototype._rebalance = function () { if (height(this.left) >= 2 + height(this.right)) { var left = this.left; if (height(left.left) >= height(left.right)) { // Left-Left case this._rightRotate(); this._updateMaxAfterRightRotate(); } else { // Left-Right case left._leftRotate(); this._rightRotate(); this._updateMaxAfterRightRotate(); } } else if (height(this.right) >= 2 + height(this.left)) { var right = this.right; if (height(right.right) >= height(right.left)) { // Right-Right case this._leftRotate(); this._updateMaxAfterLeftRotate(); } else { // Right-Left case right._rightRotate(); this._leftRotate(); this._updateMaxAfterLeftRotate(); } } }; Node.prototype.insert = function (record) { if (record.low < this.key) { // Insert into left subtree if (this.left === undefined) { this.left = new Node(this.intervalTree, record); this.left.parent = this; } else { this.left.insert(record); } } else { // Insert into right subtree if (this.right === undefined) { this.right = new Node(this.intervalTree, record); this.right.parent = this; } else { this.right.insert(record); } } // Update the max value of this ancestor if needed if (this.max < record.high) { this.max = record.high; } // Update height of each node this.updateHeight(); // Rebalance the tree to ensure all operations are executed in O(logn) time. This is especially // important in searching, as the tree has a high chance of degenerating without the rebalancing this._rebalance(); }; Node.prototype._getOverlappingRecords = function (currentNode, low, high) { if (currentNode.key <= high && low <= currentNode.getNodeHigh()) { // Nodes are overlapping, check if individual records in the node are overlapping var tempResults = []; for (var i = 0; i < currentNode.records.length; i++) { if (currentNode.records[i].high >= low) { tempResults.push(currentNode.records[i]); } } return tempResults; } return []; }; Node.prototype.search = function (low, high) { // Don't search nodes that don't exist if (this === undefined) { return []; } var leftSearch = []; var ownSearch = []; var rightSearch = []; // If interval is to the right of the rightmost point of any interval in this node and all its // children, there won't be any matches if (low > this.max) { return []; } // Search left children if (this.left !== undefined && this.left.max >= low) { leftSearch = this.left.search(low, high); } // Check this node ownSearch = this._getOverlappingRecords(this, low, high); // If interval is to the left of the start of this interval, then it can't be in any child to // the right if (high < this.key) { return leftSearch.concat(ownSearch); } // Otherwise, search right children if (this.right !== undefined) { rightSearch = this.right.search(low, high); } // Return accumulated results, if any return leftSearch.concat(ownSearch, rightSearch); }; // Searches for a node by a `key` value Node.prototype.searchExisting = function (low) { if (this === undefined) { return undefined; } if (this.key === low) { return this; } else if (low < this.key) { if (this.left !== undefined) { return this.left.searchExisting(low); } } else { if (this.right !== undefined) { return this.right.searchExisting(low); } } return undefined; }; // Returns the smallest node of the subtree Node.prototype._minValue = function () { if (this.left === undefined) { return this; } else { return this.left._minValue(); } }; Node.prototype.remove = function (node) { var parent = this.parent; if (node.key < this.key) { // Node to be removed is on the left side if (this.left !== undefined) { return this.left.remove(node); } else { return undefined; } } else if (node.key > this.key) { // Node to be removed is on the right side if (this.right !== undefined) { return this.right.remove(node); } else { return undefined; } } else { if (this.left !== undefined && this.right !== undefined) { // Node has two children var minValue = this.right._minValue(); this.key = minValue.key; this.records = minValue.records; return this.right.remove(this); } else if (parent.left === this) { // One child or no child case on left side if (this.right !== undefined) { parent.left = this.right; this.right.parent = parent; } else { parent.left = this.left; if (this.left !== undefined) { this.left.parent = parent; } } parent.updateMaxOfParents(); parent.updateHeight(); parent._rebalance(); return this; } else if (parent.right === this) { // One child or no child case on right side if (this.right !== undefined) { parent.right = this.right; this.right.parent = parent; } else { parent.right = this.left; if (this.left !== undefined) { this.left.parent = parent; } } parent.updateMaxOfParents(); parent.updateHeight(); parent._rebalance(); return this; } } }; return Node; }()); exports.Node = Node; var IntervalTree = /** @class */ (function () { function IntervalTree() { this.count = 0; } IntervalTree.prototype.insert = function (record) { if (record.low > record.high) { throw new Error('`low` value must be lower or equal to `high` value'); } if (this.root === undefined) { // Base case: Tree is empty, new node becomes root this.root = new Node(this, record); this.count++; return true; } else { // Otherwise, check if node already exists with the same key var node = this.root.searchExisting(record.low); if (node !== undefined) { // Check the records in this node if there already is the one with same low, high, data for (var i = 0; i < node.records.length; i++) { if (isSame(node.records[i], record)) { // This record is same as the one we're trying to insert; return false to indicate // nothing has been inserted return false; } } // Add the record to the node node.records.push(record); // Update max of the node and its parents if necessary if (record.high > node.max) { node.max = record.high; if (node.parent) { node.parent.updateMaxOfParents(); } } this.count++; return true; } else { // Node with this key doesn't already exist. Call insert function on root's node this.root.insert(record); this.count++; return true; } } }; IntervalTree.prototype.search = function (low, high) { if (this.root === undefined) { // Tree is empty; return empty array return []; } else { return this.root.search(low, high); } }; IntervalTree.prototype.remove = function (record) { if (this.root === undefined) { // Tree is empty; nothing to remove return false; } else { var node = this.root.searchExisting(record.low); if (node === undefined) { return false; } else if (node.records.length > 1) { var removedRecord = void 0; // Node with this key has 2 or more records. Find the one we need and remove it for (var i = 0; i < node.records.length; i++) { if (isSame(node.records[i], record)) { removedRecord = node.records[i]; node.records.splice(i, 1); break; } } if (removedRecord) { removedRecord = undefined; // Update max of that node and its parents if necessary if (record.high === node.max) { var nodeHigh = node.getNodeHigh(); if (node.left !== undefined && node.right !== undefined) { node.max = Math.max(Math.max(node.left.max, node.right.max), nodeHigh); } else if (node.left !== undefined && node.right === undefined) { node.max = Math.max(node.left.max, nodeHigh); } else if (node.left === undefined && node.right !== undefined) { node.max = Math.max(node.right.max, nodeHigh); } else { node.max = nodeHigh; } if (node.parent) { node.parent.updateMaxOfParents(); } } this.count--; return true; } else { return false; } } else if (node.records.length === 1) { // Node with this key has only 1 record. Check if the remaining record in this node is // actually the one we want to remove if (isSame(node.records[0], record)) { // The remaining record is the one we want to remove. Remove the whole node from the tree if (this.root.key === node.key) { // We're removing the root element. Create a dummy node that will temporarily take // root's parent role var rootParent = new Node(this, { low: record.low, high: record.low }); rootParent.left = this.root; this.root.parent = rootParent; var removedNode = this.root.remove(node); this.root = rootParent.left; if (this.root !== undefined) { this.root.parent = undefined; } if (removedNode) { removedNode = undefined; this.count--; return true; } else { return false; } } else { var removedNode = this.root.remove(node); if (removedNode) { removedNode = undefined; this.count--; return true; } else { return false; } } } else { // The remaining record is not the one we want to remove return false; } } else { // No records at all in this node?! Shouldn't happen return false; } } }; IntervalTree.prototype.inOrder = function () { return new InOrder(this.root); }; IntervalTree.prototype.preOrder = function () { return new PreOrder(this.root); }; return IntervalTree; }()); exports.IntervalTree = IntervalTree; var DataIntervalTree = /** @class */ (function () { function DataIntervalTree() { this.tree = new IntervalTree(); } DataIntervalTree.prototype.insert = function (low, high, data) { return this.tree.insert({ low: low, high: high, data: data }); }; DataIntervalTree.prototype.remove = function (low, high, data) { return this.tree.remove({ low: low, high: high, data: data }); }; DataIntervalTree.prototype.search = function (low, high) { return this.tree.search(low, high).map(function (v) { return v.data; }); }; DataIntervalTree.prototype.inOrder = function () { return this.tree.inOrder(); }; DataIntervalTree.prototype.preOrder = function () { return this.tree.preOrder(); }; Object.defineProperty(DataIntervalTree.prototype, "count", { get: function () { return this.tree.count; }, enumerable: true, configurable: true }); return DataIntervalTree; }()); exports["default"] = DataIntervalTree; var InOrder = /** @class */ (function () { function InOrder(startNode) { this.stack = []; if (startNode !== undefined) { this.push(startNode); } } InOrder.prototype.next = function () { // Will only happen if stack is empty and pop is called if (this.currentNode === undefined) { return { done: true, value: undefined, }; } // Process this node if (this.i < this.currentNode.records.length) { return { done: false, value: this.currentNode.records[this.i++], }; } if (this.currentNode.right !== undefined) { this.push(this.currentNode.right); } else { // Might pop the last and set this.currentNode = undefined this.pop(); } return this.next(); }; InOrder.prototype.push = function (node) { this.currentNode = node; this.i = 0; while (this.currentNode.left !== undefined) { this.stack.push(this.currentNode); this.currentNode = this.currentNode.left; } }; InOrder.prototype.pop = function () { this.currentNode = this.stack.pop(); this.i = 0; }; return InOrder; }()); exports.InOrder = InOrder; if (typeof Symbol === 'function') { InOrder.prototype[Symbol.iterator] = function () { return this; }; } var PreOrder = /** @class */ (function () { function PreOrder(startNode) { this.stack = []; this.i = 0; this.currentNode = startNode; } PreOrder.prototype.next = function () { // Will only happen if stack is empty and pop is called, // which only happens if there is no right node (i.e we are done) if (this.currentNode === undefined) { return { done: true, value: undefined, }; } // Process this node if (this.i < this.currentNode.records.length) { return { done: false, value: this.currentNode.records[this.i++], }; } if (this.currentNode.right !== undefined) { this.push(this.currentNode.right); } if (this.currentNode.left !== undefined) { this.push(this.currentNode.left); } this.pop(); return this.next(); }; PreOrder.prototype.push = function (node) { this.stack.push(node); }; PreOrder.prototype.pop = function () { this.currentNode = this.stack.pop(); this.i = 0; }; return PreOrder; }()); exports.PreOrder = PreOrder; if (typeof Symbol === 'function') { PreOrder.prototype[Symbol.iterator] = function () { return this; }; } //# sourceMappingURL=index.js.map /***/ }), /***/ "./node_modules/shallowequal/index.js": /*!********************************************!*\ !*** ./node_modules/shallowequal/index.js ***! \********************************************/ /***/ ((module) => { // module.exports = function shallowEqual(objA, objB, compare, compareContext) { var ret = compare ? compare.call(compareContext, objA, objB) : void 0; if (ret !== void 0) { return !!ret; } if (objA === objB) { return true; } if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) { return false; } var keysA = Object.keys(objA); var keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB); // Test for A's keys different from B. for (var idx = 0; idx < keysA.length; idx++) { var key = keysA[idx]; if (!bHasOwnProperty(key)) { return false; } var valueA = objA[key]; var valueB = objB[key]; ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0; if (ret === false || (ret === void 0 && valueA !== valueB)) { return false; } } return true; }; /***/ }), /***/ "./src/doc_controller.ts": /*!*******************************!*\ !*** ./src/doc_controller.ts ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ DocController: () => (/* binding */ DocController), /* harmony export */ DocOptions: () => (/* binding */ DocOptions) /* harmony export */ }); /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "./src/entries/helpers.ts"); /* harmony import */ var jspdf__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jspdf */ "jspdf"); /* harmony import */ var jspdf__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jspdf__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _helper_survey__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helper_survey */ "./src/helper_survey.ts"); /* harmony import */ var _jspdf_plugins_acroform_radio__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./jspdf_plugins/acroform_radio */ "./src/jspdf_plugins/acroform_radio.ts"); /* harmony import */ var _jspdf_plugins_acroform_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./jspdf_plugins/acroform.js */ "./src/jspdf_plugins/acroform.js"); /* harmony import */ var _jspdf_plugins_from_html_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./jspdf_plugins/from_html.js */ "./src/jspdf_plugins/from_html.js"); // import Fonts from './fonts'; var DocOptions = /** @class */ (function () { function DocOptions(options) { var _this = this; this._base64Normal = undefined; this._base64Bold = undefined; if (typeof options.orientation === 'undefined') { if (typeof options.format === 'undefined' || options.format[0] < options.format[1]) { this._orientation = 'p'; } else this._orientation = 'l'; } else this._orientation = options.orientation; this._format = options.format || 'a4'; if (Array.isArray(this._format)) { this._format = this._format.map(function (f) { return f * DocOptions.MM_TO_PT; }); } this._fontSize = options.fontSize || DocOptions.FONT_SIZE; if (!options.fontName) { if (!DocOptions.SEGOE_BOLD && !DocOptions.SEGOE_NORMAL) { this._fontName = _helper_survey__WEBPACK_IMPORTED_MODULE_2__.SurveyHelper.STANDARD_FONT; } else { this._fontName = 'segoe'; } } else { this._fontName = options.fontName; } if ((typeof options.fontName !== 'undefined' && (typeof options.base64Normal !== 'undefined' || typeof options.base64Bold !== 'undefined'))) { this._base64Normal = options.base64Normal || options.base64Bold; this._base64Bold = options.base64Bold || options.base64Normal; } else if (this.fontName === 'segoe') { // this._base64Normal = Fonts.SEGOE_NORMAL; // this._base64Bold = Fonts.SEGOE_BOLD; this._base64Normal = DocOptions.SEGOE_NORMAL; this._base64Bold = DocOptions.SEGOE_BOLD; } this._margins = _helper_survey__WEBPACK_IMPORTED_MODULE_2__.SurveyHelper.clone(options.margins); if (typeof this._margins === 'undefined') { this._margins = {}; } if (typeof this._margins.top === 'undefined') { this._margins.top = 10.0; } if (typeof this._margins.bot === 'undefined') { this._margins.bot = 10.0; } if (typeof this._margins.left === 'undefined') { this._margins.left = 10.0; } if (typeof this._margins.right === 'undefined') { this._margins.right = 10.0; } Object.keys(this._margins).forEach(function (name) { _this._margins[name] = _this._margins[name] * DocOptions.MM_TO_PT; }); this._htmlRenderAs = options.htmlRenderAs || 'auto'; this._matrixRenderAs = options.matrixRenderAs || 'auto'; this._readonlyRenderAs = options.readonlyRenderAs || 'auto'; this._compress = options.compress || false; this._applyImageFit = options.applyImageFit || false; this._useLegacyBooleanRendering = options.useLegacyBooleanRendering || false; this._isRTL = options.isRTL || false; this._tagboxSelectedChoicesOnly = options.tagboxSelectedChoicesOnly || false; } Object.defineProperty(DocOptions.prototype, "leftTopPoint", { get: function () { return { xLeft: this.margins.left, yTop: this.margins.top }; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "fontSize", { get: function () { return this._fontSize; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "fontName", { get: function () { return this._fontName; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "base64Normal", { get: function () { return this._base64Normal; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "base64Bold", { get: function () { return this._base64Bold; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "useCustomFontInHtml", { get: function () { return this._useCustomFontInHtml; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "margins", { get: function () { return this._margins; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "format", { get: function () { return this._format; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "orientation", { get: function () { return this._orientation; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "htmlRenderAs", { get: function () { return this._htmlRenderAs; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "matrixRenderAs", { get: function () { return this._matrixRenderAs; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "readonlyRenderAs", { get: function () { return this._readonlyRenderAs; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "compress", { get: function () { return this._compress; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "applyImageFit", { get: function () { return this._applyImageFit; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "useLegacyBooleanRendering", { get: function () { return this._useLegacyBooleanRendering; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "isRTL", { get: function () { return this._isRTL; }, enumerable: false, configurable: true }); Object.defineProperty(DocOptions.prototype, "tagboxSelectedChoicesOnly", { get: function () { return this._tagboxSelectedChoicesOnly; }, enumerable: false, configurable: true }); DocOptions.MM_TO_PT = 72 / 25.4; DocOptions.FONT_SIZE = 14; return DocOptions; }()); /** * The `DocController` object includes an API that allows you to configure the resulting PDF document. You can access this object within functions that handle the `SurveyPDF`'s [`onRender...`](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf#onRenderFooter) events. * * [View Demo](https://surveyjs.io/pdf-generator/examples/how-to-use-adorners-in-pdf-forms/ (linkStyle)) */ var DocController = /** @class */ (function (_super) { (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__extends)(DocController, _super); function DocController(options) { if (options === void 0) { options = {}; } var _this = _super.call(this, options) || this; var jspdfOptions = { orientation: _this.orientation, unit: 'pt', format: _this.format, compress: _this.compress }; _this._doc = new jspdf__WEBPACK_IMPORTED_MODULE_1__.jsPDF(jspdfOptions); if (typeof _this.base64Normal !== 'undefined' && !_helper_survey__WEBPACK_IMPORTED_MODULE_2__.SurveyHelper.isFontExist(_this, _this.fontName)) { DocController.addFont(_this.fontName, _this.base64Normal, 'normal'); DocController.addFont(_this.fontName, _this.base64Bold, 'bold'); _this._doc = new jspdf__WEBPACK_IMPORTED_MODULE_1__.jsPDF(jspdfOptions); } (0,_jspdf_plugins_acroform_radio__WEBPACK_IMPORTED_MODULE_3__["default"])(_this._doc); _this._useCustomFontInHtml = options.useCustomFontInHtml && _helper_survey__WEBPACK_IMPORTED_MODULE_2__.SurveyHelper.isFontExist(_this, _this.fontName); _this._helperDoc = new jspdf__WEBPACK_IMPORTED_MODULE_1__.jsPDF(jspdfOptions); _this._doc.setFont(_this.fontName); _this._helperDoc.setFont(_this.fontName); _this._doc.setFontSize(_this.fontSize); _this._helperDoc.setFontSize(_this.fontSize); _this._fontStyle = 'normal'; _this.marginsStack = []; return _this; } DocController.addFont = function (fontName, base64, fontStyle) { var font = DocController.customFonts[fontName]; if (!font) { font = {}; DocController.customFonts[fontName] = font; } font[fontStyle] = base64; var addFontCallback = function () { var customFont = DocController.customFonts[fontName]; if (!!customFont && !!customFont[fontStyle]) { var fontFile = "".concat(fontName, "-").concat(fontStyle, ".ttf"); this.addFileToVFS(fontFile, customFont[fontStyle]); this.addFont(fontFile, fontName, fontStyle); } }; jspdf__WEBPACK_IMPORTED_MODULE_1__.jsPDF.API.events.push(['addFonts', addFontCallback]); }; Object.defineProperty(DocController.prototype, "doc", { get: function () { return this._doc; }, enumerable: false, configurable: true }); Object.defineProperty(DocController.prototype, "helperDoc", { get: function () { return this._helperDoc; }, enumerable: false, configurable: true }); Object.defineProperty(DocController.prototype, "fontName", { get: function () { return this._fontName; }, set: function (fontName) { this._fontName = fontName; this._doc.setFont(fontName); this._helperDoc.setFont(fontName); }, enumerable: false, configurable: true }); Object.defineProperty(DocController.prototype, "fontSize", { get: function () { return this._fontSize; }, set: function (fontSize) { this._fontSize = fontSize; this._doc.setFontSize(fontSize); this._helperDoc.setFontSize(fontSize); }, enumerable: false, configurable: true }); Object.defineProperty(DocController.prototype, "fontStyle", { get: function () { return this._fontStyle; }, set: function (fontStyle) { this._fontStyle = fontStyle; this._doc.setFont(this._fontName, fontStyle); this._helperDoc.setFont(this._fontName, fontStyle); }, enumerable: false, configurable: true }); DocController.prototype.measureText = function (text, fontStyle, fontSize) { var _this = this; if (text === void 0) { text = 1; } if (fontStyle === void 0) { fontStyle = this._fontStyle; } if (fontSize === void 0) { fontSize = this._fontSize; } var oldFontSize = this._helperDoc.getFontSize(); this._helperDoc.setFontSize(fontSize); this._helperDoc.setFont(this._fontName, fontStyle); var height = this._helperDoc.getLineHeight() / this._helperDoc.internal.scaleFactor; var width = 0.0; if (typeof text === 'number') { width = height * text; } else { text = typeof text === 'string' ? text : _helper_survey__WEBPACK_IMPORTED_MODULE_2__.SurveyHelper.getLocString(text); width = text.split('').reduce(function (sm, cr) { return sm + _this._helperDoc.getTextWidth(cr); }, 0.0); } this._helperDoc.setFontSize(oldFontSize); this._helperDoc.setFont(this._fontName, 'normal'); return { width: width, height: height }; }; Object.defineProperty(DocController.prototype, "unitWidth", { /** * The width of one character in pixels. */ get: function () { return this.measureText().width; }, enumerable: false, configurable: true }); Object.defineProperty(DocController.prototype, "unitHeight", { /** * The heigth of one character in pixels. */ get: function () { return this.measureText().height; }, enumerable: false, configurable: true }); DocController.prototype.pushMargins = function (left, right) { this.marginsStack.push({ left: this.margins.left, right: this.margins.right }); if (typeof left !== 'undefined') this.margins.left = left; if (typeof right !== 'undefined') this.margins.right = right; }; DocController.prototype.popMargins = function () { var margins = this.marginsStack.pop(); this.margins.left = margins.left; this.margins.right = margins.right; }; Object.defineProperty(DocController.prototype, "paperWidth", { /** * The width of a PDF page in pixels. */ get: function () { return this.doc.internal.pageSize.width; }, enumerable: false, configurable: true }); Object.defineProperty(DocController.prototype, "paperHeight", { /** * The height of a PDF page in pixels. */ get: function () { return this.doc.internal.pageSize.height; }, enumerable: false, configurable: true }); DocController.prototype.getNumberOfPages = function () { return this.doc.getNumberOfPages(); }; DocController.prototype.addPage = function () { this.doc.addPage(); }; DocController.prototype.getCurrentPageIndex = function () { return this.doc.getCurrentPageInfo().pageNumber - 1; }; DocController.prototype.setPage = function (index) { this.doc.setPage(index + 1); }; DocController.customFonts = {}; return DocController; }(DocOptions)); /***/ }), /***/ "./src/entries/helpers.ts": /*!********************************!*\ !*** ./src/entries/helpers.ts ***! \********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __assign: () => (/* binding */ __assign), /* harmony export */ __awaiter: () => (/* binding */ __awaiter), /* harmony export */ __decorate: () => (/* binding */ __decorate), /* harmony export */ __extends: () => (/* binding */ __extends), /* harmony export */ __generator: () => (/* binding */ __generator), /* harmony export */ __rest: () => (/* binding */ __rest), /* harmony export */ __spreadArray: () => (/* binding */ __spreadArray) /* harmony export */ }); 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== 'function' && b !== null) throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null'); extendStatics(d, b); function __() { this.constructor = d; } // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === 'function') for (var i = 0, q = Object.getOwnPropertySymbols(s); i < q.length; i++) { if (e.indexOf(q[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, q[i])) t[q[i]] = s[q[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') r = Reflect.decorate(decorators, target, key, desc); // eslint-disable-next-line no-cond-assign else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator['throw'](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), 'throw': verb(1), 'return': verb(2) }, typeof Symbol === 'function' && (g