Survey & Questionnaire Creator

Survey & Questionnaire Creator

${index + 1}. ${q.text || 'Untitled Question'}

${answerHtml}
`; }).join(''); const headerStyle = isForPdf ? `padding: 40px;` : `padding: 10px;`; const mainStyle = isForPdf ? `padding: 0 40px 40px 40px;` : `padding: 10px;`; return `

${title}

${description}

${questionsHtml}
${isForPdf ? `

Generated by Survey & Questionnaire Creator

` : ''}
`; } window.downloadPDF = () => { const { jsPDF } = window.jspdf; const pdfContainer = document.getElementById('pdf-render-container'); const surveyTitle = document.getElementById('surveyTitle')?.value || 'Survey'; if (!pdfContainer) return; pdfContainer.innerHTML = generateSurveyHtml(true); // true = for PDF const content = document.getElementById('pdf-content'); if(!content) return; const sanitizedFileName = surveyTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase(); const fileName = `${sanitizedFileName}.pdf`; html2canvas(content, { scale: 2, useCORS: true, logging: false }) .then(canvas => { const imgData = canvas.toDataURL('image/jpeg', 0.95); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const ratio = imgProps.width / imgProps.height; const scaledImgHeight = pdfWidth / ratio; let heightLeft = scaledImgHeight; let position = 0; pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, scaledImgHeight); heightLeft -= pdfHeight; while (heightLeft > 0) { position -= pdfHeight; pdf.addPage(); pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, scaledImgHeight); heightLeft -= pdfHeight; } pdf.save(fileName); pdfContainer.innerHTML = ''; }).catch(error => { console.error("Error generating PDF:", error); pdfContainer.innerHTML = ''; }); }; // --- RUN ON LOAD --- showTab(1); });
Scroll to Top