0

I am trying to use the SurveyJS "Export to PDF" feature, described here, on a form with several pages. I follow the steps for a JavaScript application (importing Javascript libraries in HEAD, adding the rest of their code after I define the JSON of the survey) and nothing happens. When I open the Javascript console, I see two errors:

Uncaught TypeError: Cannot read properties of undefined (reading 'Serializer')
    at survey.pdf.min.js:2:33043
    at survey.pdf.min.js:2:179807
    at survey.pdf.min.js:2:179813
    at survey.pdf.min.js:2:306
    at survey.pdf.min.js:2:326

survey.js:33 Uncaught ReferenceError: SurveyPDF is not defined
    at savePdf (survey_rct_wrapper.js:33:23)
    at t.action (survey_rct_wrapper.js:41:19)
    at HTMLInputElement.<anonymous> (survey.jquery.min.js:11:47630)
    at HTMLInputElement.dispatch (jquery.min.js:2:40035)
    at v.handle (jquery.min.js:2:38006)

As suggested in the comments, I tried using the unminified version of the libraries. Here is a minimal reproducible example in Jade/PUG:

doctype html
html
  head
    <!-- jsPDF library -->
    <script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.js"></script>

    <!-- SurveyJS PDF Generator library -->
    <script src="https://unpkg.com/survey-pdf/survey.pdf.js"></script>

And now the console shows more details on the source of the error:

flat_question.ts:170 Uncaught TypeError: Cannot read properties of undefined (reading 'Serializer')
    at ./src/flat_layout/flat_question.ts (flat_question.ts:170:1)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/flat_layout/flat_repository.ts (flat_rating.ts:98:61)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/helper_survey.ts (flat_textbox.ts:28:60)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/doc_controller.ts (index.js:46:1)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/survey.ts (pdf_titlepanel.ts:18:2)
    at __webpack_require__ (bootstrap:19:1)

How can I fix this issue, or find another way to export from a SurveyJS JSON form to a PDF file?

4
  • 2
    First thing to do is work with the unminified version of the library. Debugging with minified libraries is best considered impossible. Commented Apr 15 at 19:11
  • 2
    This question would be better if the steps to reproduce the issue were included in the body of the question. Commented Apr 15 at 19:21
  • @KJ I tested your snippet and did not see the button "Save as PDF". Inspecting the source code, I don't see where you call the library SurveyPDF. Commented Apr 16 at 11:34
  • @KJ Your second survey works for me too, thanks. The difference is that you include the survey-core package, which the SurveyJS team mentioned just now in a reply to a ticket. Can you please write an answer and I'll accept it? And can you please also mention the simpler methods to export multi-page surveys as PDFs? Commented Apr 16 at 14:26

1 Answer 1

2

A code snippet in the comments and the answer by the SurveyJS help desk points to the problem, which is a missing package.

It's necessary to additionally reference the survey-core package. Please refer to the following demo: View Plunker.

<script src="https://unpkg.com/[email protected]/survey.core.min.js"></script> <script src="https://unpkg.com/[email protected]/survey-js-ui.min.js"></script>

See ticket here. I suggested updating their documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.