Code Monkey home page Code Monkey logo

survey-pdf's Introduction

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

survey-pdf's People

Contributors

andrewtelnov avatar dependabot[bot] avatar dk981234 avatar dmitry-kurmanov avatar gologames avatar henritroyot avatar joshcampbell191 avatar msftenhanceprovenance avatar mviorno avatar olgalarina avatar st-1580 avatar tsv2013 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.