Supporter images et le titre du quiz en haut, taille du papier USLetter

This commit is contained in:
C. Fuhrman 2025-04-10 21:30:15 -04:00
parent 4895b2b8a7
commit 8e8bff3894

View file

@ -65,7 +65,7 @@ const DownloadQuizModal: React.FC<DownloadQuizModalProps> = ({ quiz }) => {
if (!selectedQuiz) throw new Error('Quiz not found'); if (!selectedQuiz) throw new Error('Quiz not found');
let previewHTML = ''; let previewHTML = '<h2>' + selectedQuiz.title + '</h2>';
selectedQuiz.content.forEach((giftQuestion) => { selectedQuiz.content.forEach((giftQuestion) => {
try { try {
const question = parse(giftQuestion); const question = parse(giftQuestion);
@ -76,9 +76,9 @@ const DownloadQuizModal: React.FC<DownloadQuizModalProps> = ({ quiz }) => {
}); });
} catch (error) { } catch (error) {
if (error instanceof Error) { if (error instanceof Error) {
previewHTML += ErrorTemplate(giftQuestion + '\n' + error.message); previewHTML += ErrorTemplate(giftQuestion, error.message );
} else { } else {
previewHTML += ErrorTemplate(giftQuestion + '\n' + 'Erreur inconnue'); previewHTML += ErrorTemplate(giftQuestion, 'Erreur inconnue');
} }
} }
}); });
@ -107,11 +107,12 @@ const DownloadQuizModal: React.FC<DownloadQuizModalProps> = ({ quiz }) => {
tempDiv.innerHTML = sanitizedHTML; tempDiv.innerHTML = sanitizedHTML;
document.body.appendChild(tempDiv); document.body.appendChild(tempDiv);
const canvas = await html2canvas(tempDiv, { scale: 2 }); // allowTaint and useCORS are set to true to allow cross-origin images to be used in the canvas
const canvas = await html2canvas(tempDiv, { scale: 2, useCORS: true, allowTaint: true });
document.body.removeChild(tempDiv); document.body.removeChild(tempDiv);
const pdf = new jsPDF('p', 'mm', 'a4'); const pdf = new jsPDF('p', 'mm', 'letter');
const pageWidth = pdf.internal.pageSize.width; const pageWidth = pdf.internal.pageSize.width;
const pageHeight = pdf.internal.pageSize.height; const pageHeight = pdf.internal.pageSize.height;
const margin = 10; const margin = 10;