survey-pdf 2.5.31 → 2.5.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/fesm/pdf-form-filler-shared.mjs +209 -0
  2. package/fesm/pdf-form-filler-shared.mjs.map +1 -0
  3. package/fesm/pdf-form-filler.mjs +35 -0
  4. package/fesm/pdf-form-filler.mjs.map +1 -0
  5. package/fesm/pdf-form-filler.node.mjs +27 -0
  6. package/fesm/pdf-form-filler.node.mjs.map +1 -0
  7. package/fesm/pdf-shared.mjs +2 -2
  8. package/fesm/survey.pdf.fonts.mjs +17 -0
  9. package/fesm/survey.pdf.fonts.mjs.map +1 -0
  10. package/fesm/survey.pdf.mjs +1 -1
  11. package/fesm/survey.pdf.node.mjs +1 -1
  12. package/forms-typings/entries/forms-node.d.ts +3 -0
  13. package/forms-typings/entries/forms.d.ts +3 -0
  14. package/forms-typings/pdf_forms/adapters/adapter.d.ts +3 -0
  15. package/forms-typings/pdf_forms/adapters/pdf-lib.d.ts +6 -0
  16. package/forms-typings/pdf_forms/adapters/pdfjs.d.ts +6 -0
  17. package/forms-typings/pdf_forms/forms-base.d.ts +124 -0
  18. package/forms-typings/pdf_forms/forms-node.d.ts +4 -0
  19. package/forms-typings/pdf_forms/forms.d.ts +13 -0
  20. package/forms-typings/pdf_forms/map.d.ts +7 -0
  21. package/package.json +2 -2
  22. package/pdf-form-filler.js +351 -0
  23. package/pdf-form-filler.js.map +1 -0
  24. package/pdf-form-filler.min.js +5 -0
  25. package/pdf-form-filler.min.js.LICENSE.txt +10 -0
  26. package/pdf-form-filler.node.js +340 -0
  27. package/pdf-form-filler.node.js.map +1 -0
  28. package/pdf-form-filler.node.min.js +5 -0
  29. package/pdf-form-filler.node.min.js.LICENSE.txt +10 -0
  30. package/survey.pdf.fonts.js +28 -0
  31. package/survey.pdf.fonts.js.map +1 -0
  32. package/survey.pdf.fonts.min.js +5 -0
  33. package/survey.pdf.fonts.min.js.LICENSE.txt +5 -0
  34. package/survey.pdf.js +2 -2
  35. package/survey.pdf.min.js +1 -1
  36. package/survey.pdf.min.js.LICENSE.txt +1 -1
  37. package/survey.pdf.node.js +2 -2
  38. package/survey.pdf.node.min.js +1 -1
  39. package/survey.pdf.node.min.js.LICENSE.txt +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * surveyjs - SurveyJS PDF library v2.5.31
2
+ * surveyjs - SurveyJS PDF library v2.5.33
3
3
  * Copyright (c) 2015-2026 Devsoft Baltic OÜ - http://surveyjs.io/
4
4
  * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * surveyjs - SurveyJS PDF library v2.5.31
2
+ * surveyjs - SurveyJS PDF library v2.5.33
3
3
  * Copyright (c) 2015-2026 Devsoft Baltic OÜ - http://surveyjs.io/
4
4
  * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
5
  */
@@ -0,0 +1,3 @@
1
+ export { PDFFormFiller } from '../pdf_forms/forms-node';
2
+ export { PDFLibAdapter } from '../pdf_forms/adapters/pdf-lib';
3
+ export { PDFJSAdapter } from '../pdf_forms/adapters/pdfjs';
@@ -0,0 +1,3 @@
1
+ export { PDFFormFiller } from '../pdf_forms/forms';
2
+ export { PDFLibAdapter } from '../pdf_forms/adapters/pdf-lib';
3
+ export { PDFJSAdapter } from '../pdf_forms/adapters/pdfjs';
@@ -0,0 +1,3 @@
1
+ export interface IPDFFormAdapter {
2
+ fillForm(template: string, data: any): Promise<string>;
3
+ }
@@ -0,0 +1,6 @@
1
+ import { IPDFFormAdapter } from './adapter';
2
+ export declare class PDFLibAdapter implements IPDFFormAdapter {
3
+ private pdfLibrary;
4
+ constructor(pdfLibrary: any);
5
+ fillForm(template: any, data: any): Promise<any>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { IPDFFormAdapter } from './adapter';
2
+ export declare class PDFJSAdapter implements IPDFFormAdapter {
3
+ private pdfLibrary;
4
+ constructor(pdfLibrary: any);
5
+ fillForm(template: any, data: any): Promise<any>;
6
+ }
@@ -0,0 +1,124 @@
1
+ import { IPDFFormAdapter } from './adapters/adapter';
2
+ /**
3
+ * An object that configures the [`PDFFormFiller`](https://surveyjs.io/pdf-generator/documentation/api-reference/pdfformfiller) plugin.
4
+ *
5
+ * Pass this object to the `PDFFormFiller` constructor:
6
+ *
7
+ * ```js
8
+ * const form = new PDFFormFiller.PDFFormFiller(pdfFormFillerOptions);
9
+ *
10
+ * // In modular applications:
11
+ * import { PDFFormFiller } from "survey-pdf/pdf-form-filler";
12
+ * const form = new PDFFormFiller(pdfFormFillerOptions);
13
+ * ```
14
+ *
15
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
16
+ *
17
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
18
+ */
19
+ interface IPDFFormFillerOptions {
20
+ /**
21
+ * An object that maps survey fields to PDF form fields. Object keys are survey field names and object values are PDF form field IDs.
22
+ *
23
+ * The easiest way to build a field map is to access the data object with respondent answers using the `SurveyModel`'s `data` property and replace the values with the PDF form field IDs. To find the IDs, open your PDF document in any editor that allows viewing them. Note that certain field types, such as [Checkboxes](https://surveyjs.io/form-library/examples/create-checkboxes-question-in-javascript/), [Dynamic Matrix](https://surveyjs.io/form-library/examples/dynamic-matrix-add-new-rows/), and [Dynamic Panel](https://surveyjs.io/form-library/examples/duplicate-group-of-fields-in-form/) require a different configuration. Refer to the following demos for code examples.
24
+ *
25
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
26
+ *
27
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
28
+ */
29
+ fieldMap?: any;
30
+ /**
31
+ * An object with data used to populate the PDF document.
32
+ *
33
+ * Use the [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model)'s [`data`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#data) property to access this data object.
34
+ *
35
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
36
+ *
37
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
38
+ */
39
+ data?: any;
40
+ /**
41
+ * A PDF document with interactive form fields that you want to fill.
42
+ *
43
+ * Because this document is passed on to a third-party library, the type of accepted values depends on this library.
44
+ *
45
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
46
+ *
47
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
48
+ */
49
+ pdfTemplate?: any;
50
+ /**
51
+ * An adapter that serves as a bridge between the `PDFFormFiller` plugin and a specific third-party library.
52
+ *
53
+ * SurveyJS PDF Generator provides adapters for [`pdf-lib`](https://pdf-lib.js.org/) and [PDF.js](https://mozilla.github.io/pdf.js/) out of the box. Pass the libraries to the `PDFLibAdapter` or `PDFJSAdapter` constructor and assign the resulting instance to the `pdfLibraryAdapter` property.
54
+ *
55
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
56
+ *
57
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
58
+ */
59
+ pdfLibraryAdapter?: IPDFFormAdapter;
60
+ }
61
+ /**
62
+ * A base class for the `PDFFormFiller` plugin.
63
+ */
64
+ export declare abstract class PDFFormFillerBase {
65
+ constructor(options?: IPDFFormFillerOptions);
66
+ /**
67
+ * A PDF document with interactive form fields that you want to fill.
68
+ *
69
+ * Because this document is passed on to a third-party library, the type of accepted values depends on this library.
70
+ *
71
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
72
+ *
73
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
74
+ */
75
+ pdfTemplate: any;
76
+ /**
77
+ * An object that maps survey fields to PDF form fields. Object keys are survey field names and object values are PDF form field IDs.
78
+ *
79
+ * The easiest way to build a field map is to access the data object with respondent answers using the `SurveyModel`'s `data` property and replace the values with the PDF form field IDs. To find the IDs, open your PDF document in any editor that allows viewing them. Note that certain field types, such as [Checkboxes](https://surveyjs.io/form-library/examples/create-checkboxes-question-in-javascript/), [Dynamic Matrix](https://surveyjs.io/form-library/examples/dynamic-matrix-add-new-rows/), and [Dynamic Panel](https://surveyjs.io/form-library/examples/duplicate-group-of-fields-in-form/) require a different configuration. Refer to the following demos for code examples.
80
+ *
81
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
82
+ *
83
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
84
+ */
85
+ fieldMap: any;
86
+ /**
87
+ * An object with data used to populate the PDF document.
88
+ *
89
+ * Use the [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model)'s [`data`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#data) property to access this data object.
90
+ *
91
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
92
+ *
93
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
94
+ */
95
+ data: any;
96
+ /**
97
+ * An adapter that serves as a bridge between the `PDFFormFiller` plugin and a specific third-party library.
98
+ *
99
+ * SurveyJS PDF Generator provides adapters for [`pdf-lib`](https://pdf-lib.js.org/) and [PDF.js](https://mozilla.github.io/pdf.js/) out of the box. Pass the libraries to the `PDFLibAdapter` or `PDFJSAdapter` constructor and assign the resulting instance to the `pdfLibraryAdapter` property.
100
+ *
101
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
102
+ *
103
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
104
+ */
105
+ pdfLibraryAdapter?: IPDFFormAdapter;
106
+ protected getPDFBytes(): Promise<string>;
107
+ private fromCharCode;
108
+ /**
109
+ * An asynchronous method that allows you to get PDF content in different formats.
110
+ * @param type *(Optional)* One of `"blob"`, `"bloburl"`, `"dataurlstring"`. Do not specify this parameter if you want to get raw PDF content as a string value.
111
+ */
112
+ raw(type?: 'blob' | 'bloburl' | 'dataurlstring'): Promise<string | Blob>;
113
+ protected abstract saveToFile(pdfBytes: string, fileName: string): Promise<void>;
114
+ /**
115
+ * An asynchronous method that starts to download the filled PDF form in the web browser.
116
+ *
117
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
118
+ *
119
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
120
+ * @param fileName *(Optional)* A file name with the ".pdf" extension. Default value: `"FilledForm.pdf"`.
121
+ */
122
+ save(fileName?: string): Promise<void>;
123
+ }
124
+ export {};
@@ -0,0 +1,4 @@
1
+ import { PDFFormFillerBase } from './forms-base';
2
+ export declare class PDFFormFiller extends PDFFormFillerBase {
3
+ saveToFile(pdfBytes: string, fileName: string): Promise<void>;
4
+ }
@@ -0,0 +1,13 @@
1
+ import { PDFFormFillerBase } from './forms-base';
2
+ /**
3
+ * A plugin that enables you to fill interactive fields in existing PDF forms.
4
+ *
5
+ * This plugin requires a third-party library, such as [`pdf-lib`](https://pdf-lib.js.org/) or [PDF.js](https://mozilla.github.io/pdf.js/):
6
+ *
7
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
8
+ *
9
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
10
+ */
11
+ export declare class PDFFormFiller extends PDFFormFillerBase {
12
+ protected saveToFile(pdfBytes: string, fileName: string): Promise<void>;
13
+ }
@@ -0,0 +1,7 @@
1
+ export default class FormsMap {
2
+ private map;
3
+ private res;
4
+ constructor(map: any);
5
+ private mapDataRecursive;
6
+ mapData(data: any): any;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "survey-pdf",
3
- "version": "2.5.31",
3
+ "version": "2.5.33",
4
4
  "homepage": "https://surveyjs.io/",
5
5
  "author": "DevSoft Baltic OÜ <info@devsoftbaltic.com>",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "typings": "./typings/entries/pdf.d.ts",
38
38
  "peerDependencies": {
39
- "survey-core": "2.5.31"
39
+ "survey-core": "2.5.33"
40
40
  },
41
41
  "dependencies": {
42
42
  "@types/node-fetch": "^2",
@@ -0,0 +1,351 @@
1
+ /*!
2
+ * surveyjs - SurveyJS PDF library v2.5.33
3
+ * Copyright (c) 2015-2026 Devsoft Baltic OÜ - http://surveyjs.io/
4
+ * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
+ */
6
+
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.PDFFormFiller = {}));
11
+ })(this, (function (exports) { 'use strict';
12
+
13
+ /******************************************************************************
14
+ Copyright (c) Microsoft Corporation.
15
+
16
+ Permission to use, copy, modify, and/or distribute this software for any
17
+ purpose with or without fee is hereby granted.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
+ PERFORMANCE OF THIS SOFTWARE.
26
+ ***************************************************************************** */
27
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
28
+
29
+ var extendStatics = function(d, b) {
30
+ extendStatics = Object.setPrototypeOf ||
31
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
33
+ return extendStatics(d, b);
34
+ };
35
+
36
+ function __extends(d, b) {
37
+ if (typeof b !== "function" && b !== null)
38
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
39
+ extendStatics(d, b);
40
+ function __() { this.constructor = d; }
41
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
42
+ }
43
+
44
+ function __awaiter(thisArg, _arguments, P, generator) {
45
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
46
+ return new (P || (P = Promise))(function (resolve, reject) {
47
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
48
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
49
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
50
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
51
+ });
52
+ }
53
+
54
+ function __generator(thisArg, body) {
55
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
56
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
57
+ function verb(n) { return function (v) { return step([n, v]); }; }
58
+ function step(op) {
59
+ if (f) throw new TypeError("Generator is already executing.");
60
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
62
+ if (y = 0, t) op = [op[0] & 2, t.value];
63
+ switch (op[0]) {
64
+ case 0: case 1: t = op; break;
65
+ case 4: _.label++; return { value: op[1], done: false };
66
+ case 5: _.label++; y = op[1]; op = [0]; continue;
67
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
68
+ default:
69
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
70
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
71
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
72
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
73
+ if (t[2]) _.ops.pop();
74
+ _.trys.pop(); continue;
75
+ }
76
+ op = body.call(thisArg, _);
77
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
78
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
79
+ }
80
+ }
81
+
82
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
83
+ var e = new Error(message);
84
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
85
+ };
86
+
87
+ var FormsMap = /** @class */ (function () {
88
+ function FormsMap(map) {
89
+ this.map = map;
90
+ this.res = {};
91
+ }
92
+ FormsMap.prototype.mapDataRecursive = function (data, map) {
93
+ var _this = this;
94
+ if (data === undefined || data === null)
95
+ return;
96
+ if (typeof (data) !== 'object') {
97
+ if (Array.isArray(map)) {
98
+ map.forEach(function (m) {
99
+ _this.mapDataRecursive(data, m);
100
+ });
101
+ return;
102
+ }
103
+ if (typeof (map) !== 'object') {
104
+ this.res[map] = data;
105
+ }
106
+ else {
107
+ this.res[map[data].field] = map[data].value;
108
+ }
109
+ return;
110
+ }
111
+ if (Array.isArray(data)) {
112
+ data.forEach(function (d, i) {
113
+ _this.mapDataRecursive(d, Array.isArray(map) ? map[i] : map);
114
+ });
115
+ return;
116
+ }
117
+ Object.keys(data).forEach(function (key) {
118
+ _this.mapDataRecursive(data[key], map[key]);
119
+ });
120
+ };
121
+ FormsMap.prototype.mapData = function (data) {
122
+ this.res = {};
123
+ this.mapDataRecursive(data, this.map);
124
+ return this.res;
125
+ };
126
+ return FormsMap;
127
+ }());
128
+
129
+ /**
130
+ * A base class for the `PDFFormFiller` plugin.
131
+ */
132
+ var PDFFormFillerBase = /** @class */ (function () {
133
+ function PDFFormFillerBase(options) {
134
+ if (options) {
135
+ this.data = options.data;
136
+ this.fieldMap = options.fieldMap;
137
+ this.pdfTemplate = options.pdfTemplate;
138
+ this.pdfLibraryAdapter = options.pdfLibraryAdapter;
139
+ }
140
+ }
141
+ PDFFormFillerBase.prototype.getPDFBytes = function () {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var map, plainData;
144
+ var _a;
145
+ return __generator(this, function (_b) {
146
+ switch (_b.label) {
147
+ case 0:
148
+ map = new FormsMap(this.fieldMap);
149
+ plainData = map.mapData(this.data);
150
+ return [4 /*yield*/, ((_a = this.pdfLibraryAdapter) === null || _a === void 0 ? void 0 : _a.fillForm(this.pdfTemplate, plainData))];
151
+ case 1: return [2 /*return*/, _b.sent()];
152
+ }
153
+ });
154
+ });
155
+ };
156
+ PDFFormFillerBase.prototype.fromCharCode = function (array) {
157
+ var strings = [];
158
+ var chunkSize = 0xffff;
159
+ for (var i = 0; i < array.length; i += chunkSize) {
160
+ var chunk = Array.prototype.slice.call(array, i, i + chunkSize);
161
+ strings.push(String.fromCharCode.apply(null, chunk));
162
+ }
163
+ return strings.join('');
164
+ };
165
+ /**
166
+ * An asynchronous method that allows you to get PDF content in different formats.
167
+ * @param type *(Optional)* One of `"blob"`, `"bloburl"`, `"dataurlstring"`. Do not specify this parameter if you want to get raw PDF content as a string value.
168
+ */
169
+ PDFFormFillerBase.prototype.raw = function (type) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ var pdfBytes, blob;
172
+ return __generator(this, function (_a) {
173
+ switch (_a.label) {
174
+ case 0: return [4 /*yield*/, this.getPDFBytes()];
175
+ case 1:
176
+ pdfBytes = _a.sent();
177
+ if (!type || !pdfBytes)
178
+ return [2 /*return*/, pdfBytes];
179
+ if (type == 'dataurlstring')
180
+ return [2 /*return*/, 'data:application/pdf;base64,' + btoa(this.fromCharCode(pdfBytes))];
181
+ blob = new Blob([pdfBytes], { type: 'application/pdf' });
182
+ if (type == 'blob')
183
+ return [2 /*return*/, blob];
184
+ if (type == 'bloburl')
185
+ return [2 /*return*/, URL.createObjectURL(blob)];
186
+ return [2 /*return*/, pdfBytes];
187
+ }
188
+ });
189
+ });
190
+ };
191
+ /**
192
+ * An asynchronous method that starts to download the filled PDF form in the web browser.
193
+ *
194
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
195
+ *
196
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
197
+ * @param fileName *(Optional)* A file name with the ".pdf" extension. Default value: `"FilledForm.pdf"`.
198
+ */
199
+ PDFFormFillerBase.prototype.save = function () {
200
+ return __awaiter(this, arguments, void 0, function (fileName) {
201
+ var pdfBytes;
202
+ if (fileName === void 0) { fileName = 'FilledForm.pdf'; }
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0: return [4 /*yield*/, this.getPDFBytes()];
206
+ case 1:
207
+ pdfBytes = _a.sent();
208
+ if (!pdfBytes)
209
+ return [2 /*return*/];
210
+ return [4 /*yield*/, this.saveToFile(pdfBytes, fileName)];
211
+ case 2:
212
+ _a.sent();
213
+ return [2 /*return*/];
214
+ }
215
+ });
216
+ });
217
+ };
218
+ return PDFFormFillerBase;
219
+ }());
220
+
221
+ /**
222
+ * A plugin that enables you to fill interactive fields in existing PDF forms.
223
+ *
224
+ * This plugin requires a third-party library, such as [`pdf-lib`](https://pdf-lib.js.org/) or [PDF.js](https://mozilla.github.io/pdf.js/):
225
+ *
226
+ * [View pdf-lib Demo](https://surveyjs.io/pdf-generator/examples/map-survey-responses-to-pdf-fields-using-pdflib/ (linkStyle))
227
+ *
228
+ * [View PDF.js Demo](https://surveyjs.io/pdf-generator/examples/fill-in-pdf-form-fields-with-dynamic-survey-data-using-pdfjs/ (linkStyle))
229
+ */
230
+ var PDFFormFiller = /** @class */ (function (_super) {
231
+ __extends(PDFFormFiller, _super);
232
+ function PDFFormFiller() {
233
+ return _super !== null && _super.apply(this, arguments) || this;
234
+ }
235
+ PDFFormFiller.prototype.saveToFile = function (pdfBytes, fileName) {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ var blob, link;
238
+ return __generator(this, function (_a) {
239
+ blob = new Blob([pdfBytes], { type: 'application/pdf' });
240
+ link = document.createElement('a');
241
+ link.href = URL.createObjectURL(blob);
242
+ link.download = fileName;
243
+ document.body.appendChild(link);
244
+ link.click();
245
+ document.body.removeChild(link);
246
+ URL.revokeObjectURL(link.href);
247
+ return [2 /*return*/];
248
+ });
249
+ });
250
+ };
251
+ return PDFFormFiller;
252
+ }(PDFFormFillerBase));
253
+
254
+ var PDFLibAdapter = /** @class */ (function () {
255
+ function PDFLibAdapter(pdfLibrary) {
256
+ this.pdfLibrary = pdfLibrary;
257
+ }
258
+ PDFLibAdapter.prototype.fillForm = function (template, data) {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var _a, PDFDocument, PDFTextField, PDFCheckBox, PDFRadioGroup, PDFDropdown, pdfDoc, form, fields;
261
+ return __generator(this, function (_b) {
262
+ switch (_b.label) {
263
+ case 0:
264
+ _a = this.pdfLibrary, PDFDocument = _a.PDFDocument, PDFTextField = _a.PDFTextField, PDFCheckBox = _a.PDFCheckBox, PDFRadioGroup = _a.PDFRadioGroup, PDFDropdown = _a.PDFDropdown;
265
+ return [4 /*yield*/, PDFDocument.load(template)];
266
+ case 1:
267
+ pdfDoc = _b.sent();
268
+ form = pdfDoc.getForm();
269
+ fields = form.getFields();
270
+ fields.forEach(function (field) {
271
+ var fieldName = field.getName();
272
+ var value = data[fieldName];
273
+ if (value === null || value === undefined)
274
+ return;
275
+ if (field instanceof PDFTextField) {
276
+ field.setText(value);
277
+ }
278
+ else if (field instanceof PDFCheckBox) {
279
+ if (value)
280
+ field.check();
281
+ else
282
+ field.uncheck();
283
+ }
284
+ else if (field instanceof PDFRadioGroup || field instanceof PDFDropdown) {
285
+ field.select(value.toString());
286
+ }
287
+ });
288
+ return [4 /*yield*/, pdfDoc.save()];
289
+ case 2: return [2 /*return*/, _b.sent()];
290
+ }
291
+ });
292
+ });
293
+ };
294
+ return PDFLibAdapter;
295
+ }());
296
+
297
+ var PDFJSAdapter = /** @class */ (function () {
298
+ function PDFJSAdapter(pdfLibrary) {
299
+ this.pdfLibrary = pdfLibrary;
300
+ }
301
+ PDFJSAdapter.prototype.fillForm = function (template, data) {
302
+ return __awaiter(this, void 0, void 0, function () {
303
+ var pdfjsLib, doc, numPages, pageNum, page, annotations;
304
+ return __generator(this, function (_a) {
305
+ switch (_a.label) {
306
+ case 0:
307
+ pdfjsLib = this.pdfLibrary;
308
+ return [4 /*yield*/, pdfjsLib.getDocument(template).promise];
309
+ case 1:
310
+ doc = _a.sent();
311
+ numPages = doc.numPages;
312
+ pageNum = 1;
313
+ _a.label = 2;
314
+ case 2:
315
+ if (!(pageNum <= numPages)) return [3 /*break*/, 6];
316
+ return [4 /*yield*/, doc.getPage(pageNum)];
317
+ case 3:
318
+ page = _a.sent();
319
+ return [4 /*yield*/, page.getAnnotations()];
320
+ case 4:
321
+ annotations = _a.sent();
322
+ annotations.forEach(function (field) {
323
+ if (field.fieldType == undefined)
324
+ return;
325
+ var value = data[field.fieldName];
326
+ if (value) {
327
+ if (field.radioButton && field.buttonValue != value) {
328
+ return;
329
+ }
330
+ doc.annotationStorage.setValue(field.id, { value: value });
331
+ }
332
+ });
333
+ _a.label = 5;
334
+ case 5:
335
+ pageNum++;
336
+ return [3 /*break*/, 2];
337
+ case 6: return [4 /*yield*/, doc.saveDocument()];
338
+ case 7: return [2 /*return*/, _a.sent()];
339
+ }
340
+ });
341
+ });
342
+ };
343
+ return PDFJSAdapter;
344
+ }());
345
+
346
+ exports.PDFFormFiller = PDFFormFiller;
347
+ exports.PDFJSAdapter = PDFJSAdapter;
348
+ exports.PDFLibAdapter = PDFLibAdapter;
349
+
350
+ }));
351
+ //# sourceMappingURL=pdf-form-filler.js.map