${title}
${citationsHtml}
Generated by Citation Format Converter
`;
pdfContainer.innerHTML = pdfContentHtml;
const contentToCapture = document.getElementById('pdf-content');
html2canvas(contentToCapture, { scale: 2, useCORS: true })
.then(canvas => {
const imgData = canvas.toDataURL('image/jpeg', 0.95);
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const ratio = canvas.width / canvas.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('converted_citations.pdf');
pdfContainer.innerHTML = '';
});
};
// Run on load with sample
convertCitations();
});