survey-pdf
v3.0.3
Published
Renders JSON-driven SurveyJS forms and their responses as PDF documents in the browser or Node.js: fillable interactive PDF forms (AcroForm) or static printouts.
Readme
SurveyJS PDF Generator: JavaScript Library for PDF Forms
SurveyJS PDF Generator is a JavaScript library that renders SurveyJS forms and collected responses as PDF documents. Generate editable PDF forms (AcroForm) for offline completion, export completed forms as read-only PDFs, or create printable copies of blank forms using the same JSON form definition you use on the web.
The survey-pdf package extends survey-core and is built on top of jsPDF. It supports React, Angular, Vue, and plain JavaScript applications. PDF files can be generated entirely in the browser or on a Node.js server without sending form definitions or response data to SurveyJS.
How It Works
SurveyJS PDF Generator uses the same JSON form definition as SurveyJS Form Library. You can generate a PDF from a blank form definition or populate it with collected response data before export.
Your application can:
- Create a SurveyJS JSON form definition with SurveyJS Survey Creator, AI, or manually.
- Render the form on the web with SurveyJS Form Library.
- Pass the same JSON definition to PDF Generator (this package).
- Optionally add collected response data.
- Generate an editable PDF form or a read-only PDF document.
- Download the PDF in the browser or generate it on a Node.js server.
Because the web form and PDF share the same SurveyJS definition, form structure, conditional visibility, expressions, localization, and value formatting can remain consistent across both outputs.
Installation
npm install survey-pdfsurvey-pdf also runs in Node.js (for example, to generate PDFs on the server after a form is submitted). See the Create PDF Forms in Node.js guide.
Usage
Create a SurveyPDF instance from the same JSON you feed to the SurveyJS Form Library, optionally assign collected responses to data, and call save():
import { SurveyPDF } from "survey-pdf";
const surveyJson = {
elements: [
{ name: "firstName", title: "Enter your first name:", type: "text" },
{ name: "satisfaction", title: "How satisfied are you?", type: "rating" }
]
};
const pdfDocOptions = {
fontSize: 12
};
const surveyPdf = new SurveyPDF(surveyJson, pdfDocOptions);
surveyPdf.data = { firstName: "Jane", satisfaction: 5 };
surveyPdf.save("survey-response.pdf");Because SurveyPDF extends SurveyModel from survey-core, all of the survey model's logic—visibility, expressions, localization, value formatting—works unchanged. See IDocOptions for available page-format, margin, font, and compression settings.
The generated document is an interactive fillable form (AcroForm) by default. To produce a static, non-interactive printout instead, set readOnly to true:
surveyPdf.readOnly = true;See Customize PDF Form Settings for this and other rendering options.
Related Packages
| Package | Purpose |
| --- | --- |
| survey-core | Platform-independent survey model (peer dependency) |
| survey-react-ui | React renderer for the web form |
| survey-angular-ui | Angular renderer for the web form |
| survey-vue3-ui | Vue 3 renderer for the web form |
| survey-js-ui | HTML/CSS/JavaScript renderer for the web form |
Get Started
Key Features
PDF Generation and Export
- Generate PDFs from SurveyJS JSON form definitions
- Export blank or completed forms
- Generate editable AcroForm PDFs or read-only documents
- Generate PDFs in the browser or Node.js
- Convert output to Blob, Base64, etc.
PDF Appearance and Layout
The appearance of generated PDF forms is customized through shared themes, layout presets, and styles config API.
Themes
Colors, shadows, and other theme-level appearance values can be inherited from the active SurveyJS theme through the same --sjs2-* design tokens used by survey-core, which helps keep web forms and generated PDFs visually aligned.
Pass an ITheme object to applyTheme() to reuse a web theme's colors, shadows, and elevation in the PDF. See PDF Appearance Customization and the PDF Generator v3 announcement.
Layout Presets
Control PDF-specific variables—spacing, sizing, typography, border radius. Import Compact (the default, optimized for dense forms and reduced page count) or Spacious (optimized for readability) from survey-pdf/layouts and pass it to applyLayout():
```js
import { Spacious } from "survey-pdf/layouts";
surveyPdf.applyLayout(Spacious);
```Styles Config API
Adjust individual elements of the form—titles, question containers, input fields, labels, panels, matrices—including colors, font size, font style, line height, padding, borders, and spacing, without rendering hacks or event handlers.
PDF Form Filler
Collect responses online with SurveyJS Form Library and then use pdf-form-filler to populate existing PDF forms with response data. Unlike SurveyPDF, which generates a new PDF from a SurveyJS form definition, pdf-form-filler writes collected SurveyJS responses into fields in an existing PDF template. See the Fill a PDF Form with Web Form Responses guide to learn more.
Documentation
For AI coding agents: https://surveyjs.io/llms.txt indexes the documentation. Any documentation page is also available as raw Markdown — append .md to its URL, for example https://surveyjs.io/pdf-generator/documentation/get-started-html-css-javascript.md.
SurveyJS Product Family
| Product | Purpose | License |
| --- | --- | --- |
| Form Library | Render dynamic forms from JSON | MIT |
| Survey Creator | Drag-and-drop form builder UI | Commercial |
| Dashboard | Visualize and analyze collected results | Commercial |
| PDF Generator | Generate editable and read-only PDFs from SurveyJS forms and responses (this package) | Commercial |
| AI Form Response Extractor | Extract responses from paper forms, PDFs, and images into a SurveyJS schema (ai-form-response-extractor) | MIT |
Build from Source
Requires Node.js 20 or later.
Clone the repo
git clone https://github.com/surveyjs/survey-pdf.git cd survey-pdfInstall dependencies
npm installsurvey-pdfdepends onsurvey-core. Thedependenciesentry inpackage.jsonpoints to../survey-library/packages/survey-core/build, so if you build against a localsurvey-librarycheckout, buildsurvey-corefirst (seesurvey-corebuild instructions). Otherwise, replace that entry with a publishedsurvey-coreversion before runningnpm install.Build the library
npm run build:allBuild output goes to the
builddirectory.npm run buildproduces the main bundle;npm run build:allalso builds the embeddable fonts bundle, the interactive-forms (pdf-form-filler) bundle, and the layout presets. Usenpm run watch:devwhile developing.Run the local examples
npm run serveThis serves the package directory at http://localhost:7777/. The examples load the bundles from
build, so runnpm run build:all(step 3) first —npm startonly rebuilds the main bundle, which leaves the form-filler examples withoutbuild/pdf-form-filler.js.The
examplesfolder contains runnable pages:examples/jspdfgenerates a PDF from a survey definition, whileexamples/forms/pdf-libandexamples/forms/pdfjsfill an existing PDF with survey responses through thepdf-liband PDF.js adapters.Run unit tests
Unit tests use Vitest in a jsdom environment. PDF output is verified by snapshotting the computed layout — see
src/helper_test.ts.npm run test # whole suite npm run test:watch # watch mode npm run test:update-snapshots # regenerate snapshots npx vitest run tests/flat_checkbox.test.ts # a single file npx vitest run -t "test name" # tests matching a substring
Licensing
SurveyJS PDF Generator requires a commercial license for each software developer who works with the SurveyJS APIs or implements the integration.
