Question T10464
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

pdf rendering questions - part B

How to display Checkbox selected items as texts, the Other option value and Translate Survey PDF to a different language

created 3 years ago

Hi,

we tried to adapt the output format in a way that unchecked boxes are not rendered in the PDF output. (This way, we get rid of long lists of non-chosen answer options) Instead, the checked answers are listed in a text box below the question. (like described here: https://surveyjs.answerdesk.io/ticket/details/t6472

We are running into three issues here:

  1. We are unable to determine the language in which questions are rendered in the PDF. They always come in the default language

  2. As answers, the PDF generator always renders what is defined as the “value” of the respective choice. We would love to render the label (or “text”) of the choice in the chosen language.

  3. When we tick the option “other (describe)”, the result displays “other” but not what we have filled in into the description.

Please see the pictures attached for a illustration of the above.

We have already had a look at this (https://github.com/surveyjs/survey-pdf/issues/29)) as well.

Thanks a ton for your help!

Comments (1)

    Hello Jan,
    Thank you for reaching out to us. We may need additional time to reply. Please stay tuned.

    Answers approved by surveyjs Support

    created 3 years ago (modified 3 years ago)

    Hello Jan,
    Thank you for the detailed explanation. We've created the following demo showing how to generate a PDF document which contains textual representation of selected Checkbox items and Other option input: https://plnkr.co/edit/IAkQsoIIoWsH9P3f.
    To localize PDF contents, we used the survey.locale to obtain the survey language and passed this value to SurveyPDF.locale. To get a check box item's display text rather than the value, call the getDisplayValue function.

    JavaScript
    function saveSurveyToPdf(filename, surveyModel, pdfWidth, pdfHeight) { ... var surveyPDF = new SurveyPDF.SurveyPDF(json, options); surveyPDF.locale = survey.locale; surveyPDF.onRenderQuestion.add(onRenderQuestion); ... } function transformCheckboxToText(question, survey) { const transformedQuestion = Survey.QuestionFactory.Instance.createQuestion( "text", question.name ); let qJSON = question.toJSON(); let newJSON = {}; for (var key in qJSON) { newJSON[key] = qJSON[key]; } transformedQuestion.fromJSON(newJSON); transformedQuestion.setSurveyImpl(survey); transformedQuestion.value = question.getDisplayValue(); return transformedQuestion; } function onRenderQuestion(sender, options) { if (options.question.getType() === 'checkbox') { let transformedQuestion = transformCheckboxToText(options.question, sender); return new Promise((resolve) => { SurveyPDF.SurveyHelper.generateQuestionFlats( sender, options.controller, transformedQuestion, SurveyPDF.SurveyHelper.createPoint(options.bricks[0], true, true) ).then((res) => { options.bricks = res; resolve(); }); }); } }

    Clipboard-File-1.png
    Please let us know if this helps. Feel free to contact us if you have any questions or require further assistance.

    Thank you,
    Jane
    SurveyJS Team

      Show previous comments (1)

        Hello Jan,
        Thank you for the update.
        To preserve question numbers in PDF, call the transformedQuestion.setPropertyValue("no", question.no) function. Please check this updated example:
        https://plnkr.co/edit/Hnize1jmemo1Rbvg.
        If you wish to remove question numbers, disable the survey.showQuestionNumbers option.

        JavaScript
        surveyPDF.showQuestionNumbers = false;

        Please let me know if you have additional  questions.

          Hi Jane,

          we have another question regarding the PDF output. Currently, conditional questions and the answers to them are not displayed on our PDF output. That's even when they are filled in. Would you have a solution for this problem? Also happy to share any further details that you might need.

          Thanks a lot,

          Jan

            Hello Jan,
            Let's discuss this question in a separate thread: T10628: Сonditional questions and their answers are not displayed on our PDF output.

            Thank you