Add page breaks
This commit is contained in:
@@ -149,35 +149,33 @@ let resumeButton = document.getElementById("resume-button");
|
||||
// Generate PDF with html2pdf.js
|
||||
function generateResume() {
|
||||
// PDF filename change depending of the light/dark mode
|
||||
if (document.body.classList.contains(darkTheme)) {
|
||||
// html2pdf.js options
|
||||
let opt = {
|
||||
margin: 0,
|
||||
filename: 'myResumeCV-dark.pdf',
|
||||
image: { type: 'jpeg', quality: 0.98 },
|
||||
html2canvas: { scale: 4, useCORS: true },
|
||||
jsPDF: { format: 'a4', orientation: 'portrait' }
|
||||
};
|
||||
html2pdf(areaCV, opt);
|
||||
} else {
|
||||
// html2pdf.js options
|
||||
let opt = {
|
||||
margin: 0,
|
||||
filename: 'myResumeCV-light.pdf',
|
||||
image: { type: 'jpeg', quality: 0.98 },
|
||||
html2canvas: { scale: 4, useCORS: true },
|
||||
jsPDF: { format: 'a4', orientation: 'portrait' }
|
||||
};
|
||||
html2pdf(areaCV, opt);
|
||||
}
|
||||
let theme = document.body.classList.contains(darkTheme) ? 'dark' : 'light';
|
||||
|
||||
// html2pdf.js options
|
||||
let opt = {
|
||||
margin: 0,
|
||||
filename: 'myResumeCV-' + theme + '.pdf',
|
||||
image: { type: 'jpeg', quality: 0.98 },
|
||||
html2canvas: { scale: 4, useCORS: true },
|
||||
jsPDF: { format: 'a4', orientation: 'portrait' },
|
||||
pagebreak: { mode: 'css', avoid: ['.experience_content', '.education_content', '.section-title'] }
|
||||
};
|
||||
|
||||
return html2pdf().set(opt).from(areaCV).toContainer().then(function () {
|
||||
// Stretch the copy being rendered to a whole number of pages, so the
|
||||
// left column background reaches the bottom of the last page.
|
||||
// 1px less avoids a blank extra page from rounding.
|
||||
let pageHeight = this.prop.pageSize.inner.px.height;
|
||||
let resume = this.prop.container.firstElementChild;
|
||||
let pages = Math.ceil(resume.offsetHeight / pageHeight);
|
||||
resume.style.minHeight = (Math.floor(pages * pageHeight) - 1) + 'px';
|
||||
}).save();
|
||||
}
|
||||
|
||||
// Action executed by clicking on the button => generation of the final PDF CV CV
|
||||
resumeButton.addEventListener("click", () => {
|
||||
// Adapt the area of the PDF
|
||||
addScaleCV();
|
||||
// Generate the PDF
|
||||
generateResume();
|
||||
// Remove adaptation after 1 second (you can choose to set more than 1 second if your PDF download time is long)
|
||||
setTimeout(removeScaleCV, 1000);
|
||||
// Generate the PDF, then remove the adaptation once it is saved
|
||||
generateResume().finally(removeScaleCV);
|
||||
});
|
||||
Reference in New Issue
Block a user