Skip to content
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Add launch jest test configuration Apr 11, 2019
doc_generator Documentation generation first steps Nov 27, 2019
docs
examples/jspdf Updated non-commercial banner Feb 14, 2020
src Updated non-commercial banner Feb 14, 2020
tests Fix custom column width in matrixdynamic for T3262 Feb 13, 2020
.gitignore Add launch jest test configuration Apr 11, 2019
CHANGELOG.md Release: 1.5.9 Feb 14, 2020
LICENSE Fix license link's anchor Sep 23, 2019
README.md
azure-pipelines-release.yml Move dst_clean to build_prod Jul 26, 2019
azure-pipelines.yml Fix yml space Aug 1, 2019
deploy_npm.sh Fixed dependencies and remove more unused files Apr 10, 2019
docupdate_npm.sh
dts_cleaner.js Improve dts_cleaner Jul 30, 2019
index.html init Apr 9, 2019
jest.config.js Remove dummy testRegex from jest.config Sep 25, 2019
package.json
tsconfig.json Return es6 to tsconfig.json May 31, 2019
tsconfig.test.json Added Jest infrastructure for unit testing Apr 10, 2019
webpack.config.js Remove unused dependencies from package.json Jan 20, 2020

README.md

PDF Export for SurveyJS

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

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.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://cdn.polyfill.io/v2/polyfill.min.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 Boolean values only true and false
  • 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

You can’t perform that action at this time.