European History Key Events Tool

European History Key Events

Select search criteria or an era to display events.

Era: ${searchCriteriaForPDF.eraName}

`; } pdfHTML += `
`; currentEventsResults.forEach(event => { const { start, end } = normalizeYear(event); let dateString; if (start === end) { dateString = start < 0 ? `${Math.abs(start)} BC/BCE` : `${start} AD/CE`; } else { const startStr = start < 0 ? `${Math.abs(start)} BC/BCE` : `${start} AD/CE`; const endStr = end < 0 ? `${Math.abs(end)} BC/BCE` : `${end} AD/CE`; dateString = `${startStr} – ${endStr}`; } pdfHTML += `

${event.event_name}

${dateString}

${event.description}

${event.region ? `
Region: ${event.region}
` : ''}
`; }); pdfOutputContainer.innerHTML = pdfHTML; pdfOutputContainer.style.display = 'block'; const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); html2canvas(pdfOutputContainer, { scale: 2, // Improves quality useCORS: true, onclone: (document) => { let clonedBody = document.body; clonedBody.style.fontFamily = "'Times New Roman', Times, serif"; clonedBody.style.color = "#000000"; clonedBody.style.backgroundColor = "#ffffff"; } }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); let pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; let position = 0; const pageMargin = 40; // 20pt top, 20pt bottom const contentWidth = pdfWidth - (2 * pageMargin); const contentHeight = pdfHeight; // This is the height of the rendered canvas for the *entire* content let heightLeft = contentHeight; const pageHeightUsable = pdf.internal.pageSize.getHeight() - (2 * pageMargin); pdf.addImage(imgData, 'PNG', pageMargin, pageMargin, contentWidth, contentHeight); heightLeft -= pageHeightUsable; while (heightLeft > 0) { position -= pageHeightUsable; // Move viewport up by one page height pdf.addPage(); pdf.addImage(imgData, 'PNG', pageMargin, position + pageMargin, contentWidth, contentHeight); heightLeft -= pageHeightUsable; } pdf.save(`european_history_events.pdf`); pdfOutputContainer.style.display = 'none'; pdfOutputContainer.innerHTML = ''; }).catch(error => { console.error("Error generating PDF:", error); alert("There was an error generating the PDF. Please try again."); pdfOutputContainer.style.display = 'none'; pdfOutputContainer.innerHTML = ''; }); } // Initialize document.addEventListener('DOMContentLoaded', () => { populateEraDropdown(); // Set the first tab as active by default document.querySelector('.eh-tab-button').click(); updateNavButtons(); // Initial nav button state });
Scroll to Top