You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: surveyjs-pdf-nodejs/README.MD
+10-8
Original file line number
Diff line number
Diff line change
@@ -22,21 +22,23 @@ To generate a PDF form in a Node.js environment, follow these steps:
22
22
23
23
1. Install the [`survey-pdf`](https://www.npmjs.com/package/survey-pdf) npm package.
24
24
25
-
2. Create a [`SurveyPDF`](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf) instance. Its constructor accepts two parameters: a survey JSON schema and a [PDF document configuration](https://surveyjs.io/pdf-generator/documentation/api-reference/idocoptions).
25
+
2. *(Optional)* If your survey contains [HTML](https://surveyjs.io/form-library/documentation/api-reference/add-custom-html-to-survey) or [Signature](https://surveyjs.io/form-library/documentation/api-reference/signature-pad-model) questions, install the [`jsdom`](https://www.npmjs.com/package/jsdom) package to create a simulated web environment in a Node.js application. Create a JSDOM instance and reference the `window` and `document` objects from the JSDOM instance in a global scope.
26
26
27
-
3. Specify the `data` property of a `SurveyPDF` instance to define question answers. If a survey contains default values and you wish to preserve them, call the `mergeData(newObj)` method instead. For more information on how to programmatically define question answers, refer to the following help topic: [Populate Form Fields](https://surveyjs.io/form-library/documentation/design-survey/pre-populate-form-fields).
27
+
3. Create a [`SurveyPDF`](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf) instance. Its constructor accepts two parameters: a survey JSON schema and a [PDF document configuration](https://surveyjs.io/pdf-generator/documentation/api-reference/idocoptions).
28
28
29
+
4. Specify the `data` property of a `SurveyPDF` instance to define question answers. If a survey contains default values and you wish to preserve them, call the `mergeData(newObj)` method instead. For more information on how to programmatically define question answers, refer to the following help topic: [Populate Form Fields](https://surveyjs.io/form-library/documentation/design-survey/pre-populate-form-fields).
29
30
30
-
4. Call the [save(fileName)](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf#save) method on the `SurveyPDF` instance to save a PDF form.
31
+
5. Call the [save(fileName)](https://surveyjs.io/pdf-generator/documentation/api-reference/surveypdf#save) method on the `SurveyPDF` instance to save a PDF form.
31
32
32
33
## Limitations
33
34
34
-
The following question types are not supported when you generate PDF forms in Node.js:
35
+
Please take into account the following restrictions when you generate PDF forms in Node.js:
In Node.js, [HTML](https://surveyjs.io/form-library/documentation/api-reference/add-custom-html-to-survey) questions do not support the `"image"` [render mode](https://surveyjs.io/pdf-generator/documentation/api-reference/idocoptions#htmlRenderAs) and complex markup.
39
+
40
+
- **Only base64-encoded images are supported**
41
+
Images embedded in a survey, such as a [survey logo](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#logo) or images from the [Image](https://surveyjs.io/form-library/documentation/api-reference/add-image-to-survey) and [Image Picker](https://surveyjs.io/form-library/documentation/api-reference/add-image-to-survey) questions, can be specified as base64-encoded strings or as URLs. However, Node.js supports only base64-encoded strings.
Copy file name to clipboardExpand all lines: surveyjs-pdf-nodejs/index.js
+53-31
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,26 @@
1
+
constjsdom=require("jsdom");
2
+
const{JSDOM}=jsdom;
1
3
constSurveyPDF=require("survey-pdf");
2
4
3
-
constsurveyPDF=newSurveyPDF.SurveyPDF({
5
+
const{ window }=newJSDOM(`...`);
6
+
global.window=window;
7
+
global.document=window.document;
8
+
9
+
constjson={
4
10
"title": "COVID-19 Screening Form",
5
-
"description": "All fields with an asterisk (*) are required fields and must be filled out in order to process information in strict confidentiality.",
6
-
"questionErrorLocation": "bottom",
11
+
"focusFirstQuestionAutomatic": false,
7
12
"pages": [
8
13
{
9
14
"name": "patient-info",
10
-
"title": "Patient Information",
11
15
"elements": [
16
+
{
17
+
"type": "html",
18
+
"name": "introMsg",
19
+
"html": "<i>All fields with an asterisk (*) are required fields and must be filled out in order to process information in strict confidentiality.</i>"
20
+
},
12
21
{
13
22
"type": "panel",
14
23
"name": "full-name",
15
-
"title": "Full name",
16
24
"elements": [
17
25
{
18
26
"type": "text",
@@ -29,7 +37,8 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
29
37
"isRequired": true,
30
38
"maxLength": 25
31
39
}
32
-
]
40
+
],
41
+
"title": "Full name"
33
42
},
34
43
{
35
44
"type": "panel",
@@ -40,14 +49,14 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
40
49
"name": "ssn",
41
50
"title": "Social Security number",
42
51
"isRequired": true,
43
-
"maxLength": 9,
44
52
"validators": [
45
53
{
46
54
"type": "regex",
47
55
"text": "Your SSN must be a 9-digit number.",
48
56
"regex": "^\\d{9}$"
49
57
}
50
-
]
58
+
],
59
+
"maxLength": 9
51
60
},
52
61
{
53
62
"type": "text",
@@ -59,11 +68,11 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
59
68
}
60
69
]
61
70
}
62
-
]
71
+
],
72
+
"title": "Patient Information"
63
73
},
64
74
{
65
-
"name": "symptoms",
66
-
"title": "Current Symptoms",
75
+
"name": "symptoms-page",
67
76
"elements": [
68
77
{
69
78
"type": "checkbox",
@@ -82,11 +91,11 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
82
91
"showNoneItem": true,
83
92
"noneText": "No symptoms"
84
93
}
85
-
]
94
+
],
95
+
"title": "Current Symptoms"
86
96
},
87
97
{
88
98
"name": "contacts",
89
-
"title": "Contacts",
90
99
"elements": [
91
100
{
92
101
"type": "boolean",
@@ -97,13 +106,17 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
97
106
"type": "radiogroup",
98
107
"name": "contacted-covid-positive",
99
108
"title": "Have you been in contact with anyone who has since tested positive for COVID-19?",
100
-
"choices": ["Yes","No","Not sure"]
109
+
"choices": [
110
+
"Yes",
111
+
"No",
112
+
"Not sure"
113
+
]
101
114
}
102
-
]
115
+
],
116
+
"title": "Contacts"
103
117
},
104
118
{
105
119
"name": "travels",
106
-
"title": "Travels",
107
120
"elements": [
108
121
{
109
122
"type": "boolean",
@@ -116,11 +129,11 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
116
129
"visibleIf": "{travelled} = true",
117
130
"title": "Where did you go?"
118
131
}
119
-
]
132
+
],
133
+
"title": "Travels"
120
134
},
121
135
{
122
136
"name": "tests",
123
-
"title": "Tests",
124
137
"elements": [
125
138
{
126
139
"type": "boolean",
@@ -135,12 +148,9 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
135
148
{
136
149
"type": "paneldynamic",
137
150
"name": "emergency-contacts",
151
+
"visibleIf": "(({tested-covid-positive} = true or {contacted-covid-positive} = 'Yes') or ({symptoms} notempty and {symptoms} notcontains 'none'))",
138
152
"title": "Emergency Contacts",
139
153
"description": "If possible, it's best to specify at least TWO emergency contacts.",
140
-
"panelsState": "firstExpanded",
141
-
"confirmDelete": true,
142
-
"panelAddText": "Add a new contact person",
143
-
"visibleIf": "(({tested-covid-positive} = true or {contacted-covid-positive} = 'Yes') or ({symptoms} notempty and {symptoms} notcontains 'none'))",
144
154
"isRequired": true,
145
155
"templateElements": [
146
156
{
@@ -166,13 +176,16 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
166
176
"title": "Phone number",
167
177
"inputType": "tel"
168
178
}
169
-
]
179
+
],
180
+
"panelsState": "firstExpanded",
181
+
"confirmDelete": true,
182
+
"panelAddText": "Add a new contact person"
170
183
}
171
-
]
184
+
],
185
+
"title": "Tests"
172
186
},
173
187
{
174
188
"name": "finalization",
175
-
"title": "Miscellaneous",
176
189
"elements": [
177
190
{
178
191
"type": "comment",
@@ -185,16 +198,24 @@ const surveyPDF = new SurveyPDF.SurveyPDF({
0 commit comments