Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

PDF : print only answered questionTemplate

  • raresh19
  • raresh19's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 3 days ago #268129 by raresh19
Hi, sorry for jumping in, i have almost 0 knowledge in coding. I have installed LimeSurvey Community Edition Version 6.8.1+241120 and before i used the basic PDF exporter that came with LimeSurvey.

Our survey have 212 question. Not all of them are visible, they show up based on answers on previews question.

When i export the PDF with the basic PDF all my question are visible, including the not answered/showed ones.

Im trying to hide this questions in the PDF, because they are not relevant and because they are to many question you can pass throw one you answer when reviewing the PDF. I tryed to modify the pdfWriter.php and add some code to filter the questions, without any success 

foreach ($questions as $question) {

    // Retrieve the raw answer from values
    $raw_answer = isset($values[$question]) ? $values[$question] : null;
    error_log("Processing Question ID: " . $question . " | Raw Answer: '" . $raw_answer . "'");

    // Trim answer to remove leading/trailing spaces
    $answer = trim($raw_answer);

    // Skip if answer is considered empty (including '0', 'NULL', null, or spaces)
    if ($answer === '' || strtolower($answer) === 'null' || $answer === '0' || $answer === ' ') {
        error_log("Skipping Question ID: " . $question . " | Reason: Empty, null, '0' or 'NULL'");
        continue;  // Skip this question and move to the next
    }

    // If not skipped, add the answer to the PDF
    $this->pdf->addAnswer($headers[$question], $answer, false);

I read about pdfreport and also tried with it. I read the manual, but there is no step by step instruction just analyze data and demo files and i tried to replicate it.

I start with a demo survey that i created to have fewer questions to test my theory. 
So in the upload file question in the end used for the pdfreport i start adding the questions text and questions answers in "{ }" to see the response.
But they are so many question in the original one. Do i need to add to every single question?

Also is there any way to filter the answered and unanswered questions? If yes, where should i look or what should i add and where?

Thank you!

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 3 days ago #268130 by DenisChenu
Replied by DenisChenu on topic PDF : print only answered questionTemplate
pdfReport are created to do report, not export.

You can do anything for the PDF file, even something totally unrelated to the response.
But yes: if you want to replace PDF export : you have to create question one by one manualy.

For the core PDF export : in my opinion, it must be rally improved !
See issues :
bugs.limesurvey.org/view.php?id=14353
and
bugs.limesurvey.org/view.php?id=16435
and
bugs.limesurvey.org/view.php?id=14297

Else : WHY THE FUCK you don't create your own subject ????
Your need are totally unrelated !
I create a new subject here :


 

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 3 days ago #268131 by DenisChenu
Replied by DenisChenu on topic PDF : print only answered questionTemplate
Why it's TOTALLY unrelated and it's better to create your own topic : PrintAnswersOnlyAnswered plugin

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 3 days ago #268132 by DenisChenu
Replied by DenisChenu on topic PDF : print only answered questionTemplate
PS : you can just replace some twig file in theme
gitlab.com/SondagesPro/ExportAndStats/Pr....twig?ref_type=heads
 

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • raresh19
  • raresh19's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 3 days ago - 1 week 3 days ago #268133 by raresh19
Replied by raresh19 on topic PDF : print only answered questionTemplate
Hi, and sorry for wrong posting, i thought i could achieve my needs with pdfReports, some of the forum post guide me in that directions.

And i didnt want to start new post on same topic, at least i thought it was the same topic, but now i see its not.

I installed the pluggin that you point me (PrintAnswersOnlyAnswered) as in the readme file.

Than i went to configuration > plugins and activate it.
Than i went again to configuration > plugins > PrintAnswersOnlyAnswered > Settings , and set it to "Yes, replace the default LimeSurvey behaviour"

Now in the my own demo survey i went to Simple plugins > Settings for plugin PrintAnswersOnlyAnswered. Here i set Hide not answered question when participant use print answsers to Yes.

But now i dont know what to do more, how do i export the responses with your plugin?

Another question i have is that in the twig file i can configure how the output looks like? Like a custom Header and footer, custom ending message a.s.o?
Last edit: 1 week 3 days ago by raresh19.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 3 days ago #268135 by DenisChenu
Replied by DenisChenu on topic PDF : print only answered questionTemplate
Oh !
You mean the Admin Export system ?
This plugin is here for PDF for ârticpant.

For admin export system you can start by hacking existing code, and after create a plugin.

Where did you try this code ? Can you puit the link to the code ?

Else: in general : always create a new subject !

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • raresh19
  • raresh19's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 3 days ago - 1 week 3 days ago #268137 by raresh19
Replied by raresh19 on topic PDF : print only answered questionTemplate
Yes, it is for admin export.

I used chatgpt and ask him how to do it.

at first he point me to search for the pdf.php file in the lime survey files, after few tries I found out that in this versions the pdfWriter.php is responsible of generating the pdf.

The original php code was looking something like this:

foreach ($questions as $question) { if (isset($values[$question]) && isset($headers[$question])) { $this->pdf->addAnswer($headers[$question], $values[$question], false);

And he point me of adding a condition in this line for skipping unanswered questions like this:

foreach ($questions as $question) { // Check if the value is non-empty before adding it to the PDF if(!empty(trim($values[$question])) && isset($headers[$question])) { $this->pdf->addAnswer($headers[$question], $values[$question], false); } }

I tried different codes like:

foreach ($questions as $question) {
    // Check if answer and header exist
    if (isset($values[$question]) && isset($headers[$question])) {
        $answer = trim($values[$question]);
        // Skip unanswered questions
        if (!empty($answer)) {
            // Add answer to the PDF
            $this->pdf->addAnswer($headers[$question], $answer, false);
        }
    }
}

or like this

foreach ($questions as $question) {
    if (isset($values[$question]) && isset($headers[$question])) {
        $answer = trim($values[$question]);
        if (!empty($answer)) {
            $this->pdf->addAnswer($headers[$question], $answer, false);
        }
    }
}

or like this

foreach ($questions as $question) {
    $answer = $values[$question];
    
    // Log raw answer for debugging
    error_log("Raw Answer for Question ID " . $question . ": " . $answer);

    // Skip if the answer is empty, null, '0', 'NULL', or any other placeholder
    if (isset($answer) && trim($answer) !== '' && strtolower($answer) !== 'null' && $answer !== '0') {
        $this->pdf->addAnswer($headers[$question], $answer, false);
    } else {
        // Log why it's skipped
        error_log("Skipping Question ID " . $question . " because it is considered unanswered.");
    }
}

or like this

foreach ($questions as $question) {
    // Retrieve the raw answer from values
    $raw_answer = isset($values[$question]) ? $values[$question] : null;
    error_log("Processing Question ID: " . $question . " | Raw Answer: '" . $raw_answer . "'");

    // Trim answer to remove leading/trailing spaces
    $answer = trim($raw_answer);

    // Skip if answer is considered empty (including '0', 'NULL', null, or spaces)
    if ($answer === '' || strtolower($answer) === 'null' || $answer === '0' || $answer === ' ') {
        error_log("Skipping Question ID: " . $question . " | Reason: Empty, null, '0' or 'NULL'");
        continue;  // Skip this question and move to the next
    }

    // If not skipped, add the answer to the PDF
    $this->pdf->addAnswer($headers[$question], $answer, false);
}


but none of this code works the pdf remains the same, I don't know how to approach this subject.

That's why I came back on pdfreport plugin and tried to filter it out because I cat set it up to send me the complete survey on my own email, and that's why I posted in that thread.
I hope now make sense. I know you are the creator of both plugins, and if you can point me how to try to approach this I will be very grateful.

But keep in mind that, I don't have a backend or IT background, I just have a bit knowledge from my hobbys.
Last edit: 1 week 3 days ago by raresh19.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 1 day ago #268156 by DenisChenu
Replied by DenisChenu on topic PDF : print only answered questionTemplate
ChatGPT are not a developer, It can only help a developer to go faster
www.limesurvey.com/index.php/customization

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • raresh19
  • raresh19's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 14 hours ago #268173 by raresh19
Replied by raresh19 on topic PDF : print only answered questionTemplate
So what to understand from here is that The only way to achieve this is by a custom plugin ?

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose