surveyjs / survey-pdf

Supplementary component to the SurveyJS Form Library to download surveys as PDF files and generate editable PDF forms.
https://surveyjs.io/pdf-generator/examples/survey-pdf-export/
Other
64 stars 32 forks source link

PDF Export with boolean type question issue with 'No' #35

Closed jbrou015 closed 3 years ago

jbrou015 commented 3 years ago

Are you requesting a feature, reporting a bug or asking a question?

Bug

What is the current behavior?

When exporting a boolean type question to pdf and answer 'No', then in the pdf it shows a checkbox but the checkbox is not checked.

What is the expected behavior?

If a user selects No for a boolean, the pdf should check the No box

How would you reproduce the current behavior (if this is a bug)?

On your example page here just select No for the last question "It was fun?". Then look at the pdf at the bottom.

Specify your

gologames commented 3 years ago

Hello,

This is not a bug. This is expected behavior. We use Checkbox Acroform entity inside PDF document to map SurveyJS boolean question. Boolean question has three states: true, false, intermediate. But Acroform checbkox only two states:true and false

So, in case of true we set true value and true label. In case of false we set false value and false label. In case of intermediate we set false value without label. False value of Acroform checbkox renders without any checked mark. This depends on render of PDF viewer application (out of our responsibility)

As a workaround you can use SurveyPDF Adorners mechanism and set value of Acroform checbkox to true before export to PDF. Here live sample of this approach

image

surveyPDF.onRenderQuestion.add((_, options) => {
        if (options.question.getType() === "boolean" &&
            !options.question.isEmpty() && options.question.value === false) {
            options.bricks[0].unfold()[2].checked = true;
        }
    });

Thanks, Alex SurveyJS Team

jbrou015 commented 3 years ago

I have tried your code but... TS2339: Property 'checked' does not exist on type 'IPdfBrick'. What am I missing? I have upgraded the libraries to 1.8.32

gologames commented 3 years ago

Hello,

IPdfBrick is common interface for all "bricks" types. CheckItemBrick and RadioItemBrick classes have checked property

Thanks, Alex SurveyJS Team