`;
pdfButtonWrapper.classList.remove('hidden');
} else {
html = `
`;
pdfButtonWrapper.classList.add('hidden');
}
certificateOutput.innerHTML = html;
if(!passed) getEl('restart-btn').onclick = () => showTab(1);
showTab(3);
}
function downloadPdf() {
if (!appData.certificateDetails) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF('landscape', 'px', 'a4');
const { name, module, date, id } = appData.certificateDetails;
doc.internal.scaleFactor = 2; // Higher resolution
doc.addPage();
doc.deletePage(1);
// A4 size in points: 595.28 x 841.89
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
// Border
doc.setDrawColor('#4f46e5');
doc.setLineWidth(5);
doc.rect(20, 20, pageWidth - 40, pageHeight - 40);
doc.setFont('helvetica', 'normal');
doc.setTextColor('#6b7280');
doc.setFontSize(20);
doc.text('Certificate of Completion', pageWidth / 2, 80, { align: 'center' });
doc.setFontSize(14);
doc.text('This certifies that', pageWidth / 2, 130, { align: 'center' });
doc.setFont('helvetica', 'bold');
doc.setTextColor('#4f46e5');
doc.setFontSize(36);
doc.text(name, pageWidth / 2, 180, { align: 'center' });
doc.setFont('helvetica', 'normal');
doc.setTextColor('#374151');
doc.setFontSize(14);
doc.text('has successfully completed the training module', pageWidth / 2, 220, { align: 'center' });
doc.setFont('helvetica', 'bold');
doc.setFontSize(22);
doc.text(`"${module}"`, pageWidth / 2, 260, { align: 'center' });
doc.setFont('helvetica', 'normal');
doc.setFontSize(12);
doc.text(`on ${date}`, pageWidth / 2, 320, { align: 'center' });
doc.setTextColor('#9ca3af');
doc.setFontSize(8);
doc.text(`Certificate ID: ${id}`, pageWidth / 2, 350, { align: 'center' });
doc.save(`Certificate-${name.replace(/\s/g, '_')}.pdf`);
}
// --- Event Listeners & Initialization ---
nextBtn.addEventListener('click', () => {
if (currentTab === 1) {
if (!validateTab(1)) return;
appData.userName = getEl('userName').value;
appData.selectedModuleKey = trainingModuleSelect.value;
startTraining();
} else if (currentTab === 2) {
nextQuestion();
}
});
prevBtn.addEventListener('click', () => {
if (currentTab > 1) showTab(currentTab - 1);
});
getEl('download-pdf-btn').addEventListener('click', downloadPdf);
// Initial load
function init() {
trainingModuleSelect.innerHTML = '';
for (const key in trainingData) {
const option = document.createElement('option');
option.value = key;
option.textContent = trainingData[key].name;
trainingModuleSelect.appendChild(option);
}
updateNavigation();
}
init();
});
Training Complete
Your score was ${appData.score} out of ${module.questions.length}.
Unfortunately, this is below the passing score of ${module.passingScore}. Please review the materials and try again.
