From 3f5fa2d88adbf3cb036c24f06715d0c686d2f5b8 Mon Sep 17 00:00:00 2001 From: David Siegfried <david.siegfried@uni-vechta.de> Date: Wed, 15 Nov 2023 17:46:47 +0000 Subject: [PATCH] fixes #3462 Closes #3462 Merge request studip/studip!2362 --- .../assets/javascripts/lib/questionnaire.js | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/resources/assets/javascripts/lib/questionnaire.js b/resources/assets/javascripts/lib/questionnaire.js index 16ee461684a..8fbbbb0775f 100644 --- a/resources/assets/javascripts/lib/questionnaire.js +++ b/resources/assets/javascripts/lib/questionnaire.js @@ -441,12 +441,20 @@ const Questionnaire = { let pdf = new pdfExporter({ orientation: 'portrait' }); + $(".questionnaire_results").addClass('print-view'); let title = $(".questionnaire_results").data('title'); + let formattedDate = new Intl.DateTimeFormat(String.locale, { + year: "numeric", + month: "long", + day: "numeric", + hour: "numeric", + minute: "numeric" + }).format(new Date()); let splitTitle = pdf.splitTextToSize(title, 180); - pdf.text(splitTitle, 25, 20); + let count_questions = $(".questionnaire_results .question").length; let questions_rendered = 0; @@ -474,7 +482,7 @@ const Questionnaire = { let height = Math.floor(160 / canvasses[i].width * canvasses[i].height); if (height_sum + height > 240 && height < 240) { pdf.addPage(); - height_sum = 0; + height_sum = 15; } pdf.addImage(imgData, 'JPEG', 25, @@ -487,6 +495,27 @@ const Questionnaire = { ); height_sum += height + 10; } + + const pages = pdf.internal.getNumberOfPages(); + + for (let i = 1; i <= pages; i++) { + let pageSize = pdf.internal.pageSize; + let pageHeight = pageSize.getHeight(); + pdf.setPage(i); + pdf.setFontSize(16); + pdf.text(splitTitle, 25, 20); + pdf.setFontSize(8); + pdf.text( + String(formattedDate), + 30, + pageHeight - 8 + ) + pdf.text( + String(i) + ' / ' + String(pages), + pageSize.getWidth() - 30, + pageHeight - 8 + ); + } pdf.save(title + '.pdf'); } }); -- GitLab