survey-pdf

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.

Usage no npm install needed!

<script type="module">
  import surveyPdf from 'https://cdn.skypack.dev/survey-pdf';
</script>

README

PDF Export for SurveyJS

SurveyJS PDF exporter library is an easy way to render SurveyJS Library surveys to PDF which can be emailed or printed.

Build Status Issues Closed issues

Features

SurveyJS PDF exporter is represented by SurveyPDF object which is a SurveyModel descendant. It inherits all the functionality of SurveyJS Model and adds PDF export specific features.

  • Render all SurveyJS questions (textboxes, checkboxes, dropdowns, etc.) with results
  • Support of SurveyJS widgets and your own custom adorners
  • Generate PDF interactive forms which can be filled inside the PDF document
  • Automatic splitting into separate pages without cuts inside the questions
  • Customizable font and sizes of page and markdown text
  • Ability to draw header and footer with logo and company information
  • API to save PDF on disk or get PDF file via raw string

Screenshots

SurveyJS PDF Exporter example page 1 SurveyJS PDF Exporter example page 2

Usage (modern ES, modules)

import * as SurveyPDF from "survey-pdf";

Usage (ES5, scripts)

Add these scripts to your web page

<!-- jsPDF library -->
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
<!-- SurveyJS Core library -->
<script src="https://unpkg.com/survey-core@latest/survey.core.min.js"></script>
<!-- SurveyPDF Exporter library -->
<script src="https://unpkg.com/survey-pdf@latest/survey.pdf.min.js"></script>

<!-- Uncomment next line to add html and markdown text support -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.6.4/showdown.min.js"></script> -->
<!-- Uncomment next line to add IE11 support -->
<!-- <script src="https://unpkg.com/jspdf/dist/polyfills.umd.js"></script> -->

Also you may load any of SurveyJS with framework scripts without loading SurveyJS Core. Look at simple package dependency diagram

SurveyJS package dependency

Example of export SurveyJS library JSON to PDF

var options = {
  fontSize: 14,
  margins: {
    left: 10,
    right: 10,
    top: 18,
    bot: 10
  }
};
//json is same as for SurveyJS Library
var surveyPDF = new SurveyPDF.SurveyPDF(json, options);

//uncomment next code to add html and markdown text support
/*var converter = new showdown.Converter();
surveyPDF.onTextMarkdown.add(function(survey, options) {
    var str = converter.makeHtml(options.text);
    str = str.substring(3);
    str = str.substring(0, str.length - 4);
    options.html = str;
});*/

surveyPDF.onRenderHeader.add(function(_, canvas) {
  canvas.drawText({
    text:
      "SurveyJS PDF | Please purchase a SurveyJS PDF developer license to use it in your app | https://surveyjs.io/Buy",
    fontSize: 10
  });
});
surveyPDF.save();

Examples

Constraints

  • No support of dynamic elements (visibleIf, buttons, validators, etc.)
  • Implied DPI 72 when set questions width
  • Question Text input types supported: text, password, color
  • Question Radiogroup not able to set readOnly for separate items
  • Question Imagepicker imagefit is always fill
  • Question Html support restricted subset of html markup
  • Question File save files via RMB in Chrome only
  • Question Panel state is always expanded
  • Question Panel Dynamic mode is only list and state default

License

Commercial