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
This example demonstrates how to generate a PDF form using the [SurveyJS](https://surveyjs.io/) form builder libraries and the Node.js server-side framework.
4
+
5
+
## Run the project
6
+
7
+
1. Install npm packages.
8
+
9
+
```
10
+
npm install
11
+
```
12
+
13
+
1. Execute the `index.js` file to generate a PDF form as a `survey-result.pdf` file. You will find this file in the project folder.
14
+
15
+
```
16
+
node index.js
17
+
```
18
+
19
+
## How to Generate PDF Forms
20
+
21
+
To generate a PDF form in a Node.js environment, follow these steps:
22
+
23
+
1. Install the [`survey-pdf`](https://www.npmjs.com/package/survey-pdf) npm package.
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).
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).
28
+
29
+
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
+
32
+
## Limitations
33
+
34
+
The following question types are not supported when you generate PDF forms in Node.js:
"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",
7
+
"pages": [
8
+
{
9
+
"name": "patient-info",
10
+
"title": "Patient Information",
11
+
"elements": [
12
+
{
13
+
"type": "panel",
14
+
"name": "full-name",
15
+
"title": "Full name",
16
+
"elements": [
17
+
{
18
+
"type": "text",
19
+
"name": "first-name",
20
+
"title": "First name",
21
+
"isRequired": true,
22
+
"maxLength": 25
23
+
},
24
+
{
25
+
"type": "text",
26
+
"name": "last-name",
27
+
"startWithNewLine": false,
28
+
"title": "Last name",
29
+
"isRequired": true,
30
+
"maxLength": 25
31
+
}
32
+
]
33
+
},
34
+
{
35
+
"type": "panel",
36
+
"name": "personal-info",
37
+
"elements": [
38
+
{
39
+
"type": "text",
40
+
"name": "ssn",
41
+
"title": "Social Security number",
42
+
"isRequired": true,
43
+
"maxLength": 9,
44
+
"validators": [
45
+
{
46
+
"type": "regex",
47
+
"text": "Your SSN must be a 9-digit number.",
48
+
"regex": "^\\d{9}$"
49
+
}
50
+
]
51
+
},
52
+
{
53
+
"type": "text",
54
+
"name": "birthdate",
55
+
"startWithNewLine": false,
56
+
"title": "Date of Birth",
57
+
"isRequired": true,
58
+
"inputType": "date"
59
+
}
60
+
]
61
+
}
62
+
]
63
+
},
64
+
{
65
+
"name": "symptoms",
66
+
"title": "Current Symptoms",
67
+
"elements": [
68
+
{
69
+
"type": "checkbox",
70
+
"name": "symptoms",
71
+
"title": "Have you experienced any of the following symptoms of COVID-19 within the last 48 hours?",
72
+
"isRequired": true,
73
+
"choices": [
74
+
"Fever or chills",
75
+
"New and persistent cough",
76
+
"Shortness of breath or difficulty breathing",
77
+
"Fatigue",
78
+
"Muscle or body aches",
79
+
"New loss of taste or smell",
80
+
"Sore throat"
81
+
],
82
+
"showNoneItem": true,
83
+
"noneText": "No symptoms"
84
+
}
85
+
]
86
+
},
87
+
{
88
+
"name": "contacts",
89
+
"title": "Contacts",
90
+
"elements": [
91
+
{
92
+
"type": "boolean",
93
+
"name": "contacted-person-with-symptoms",
94
+
"title": "Have you been in contact with anyone in the last 14 days who is experiencing these symptoms?"
95
+
},
96
+
{
97
+
"type": "radiogroup",
98
+
"name": "contacted-covid-positive",
99
+
"title": "Have you been in contact with anyone who has since tested positive for COVID-19?",
100
+
"choices": ["Yes","No","Not sure"]
101
+
}
102
+
]
103
+
},
104
+
{
105
+
"name": "travels",
106
+
"title": "Travels",
107
+
"elements": [
108
+
{
109
+
"type": "boolean",
110
+
"name": "travelled",
111
+
"title": "Have you travelled abroad in the last 14 days?"
112
+
},
113
+
{
114
+
"type": "text",
115
+
"name": "travel-destination",
116
+
"visibleIf": "{travelled} = true",
117
+
"title": "Where did you go?"
118
+
}
119
+
]
120
+
},
121
+
{
122
+
"name": "tests",
123
+
"title": "Tests",
124
+
"elements": [
125
+
{
126
+
"type": "boolean",
127
+
"name": "tested-covid-positive",
128
+
"title": "Have you tested positive for COVID-19 in the past 10 days?"
129
+
},
130
+
{
131
+
"type": "boolean",
132
+
"name": "awaiting-covid-test",
133
+
"title": "Are you currently awaiting results from a COVID-19 test?"
134
+
},
135
+
{
136
+
"type": "paneldynamic",
137
+
"name": "emergency-contacts",
138
+
"title": "Emergency Contacts",
139
+
"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'))",
0 commit comments