Add page breaks
This commit is contained in:
@@ -149,35 +149,33 @@ let resumeButton = document.getElementById("resume-button");
|
|||||||
// Generate PDF with html2pdf.js
|
// Generate PDF with html2pdf.js
|
||||||
function generateResume() {
|
function generateResume() {
|
||||||
// PDF filename change depending of the light/dark mode
|
// PDF filename change depending of the light/dark mode
|
||||||
if (document.body.classList.contains(darkTheme)) {
|
let theme = document.body.classList.contains(darkTheme) ? 'dark' : 'light';
|
||||||
// html2pdf.js options
|
|
||||||
let opt = {
|
// html2pdf.js options
|
||||||
margin: 0,
|
let opt = {
|
||||||
filename: 'myResumeCV-dark.pdf',
|
margin: 0,
|
||||||
image: { type: 'jpeg', quality: 0.98 },
|
filename: 'myResumeCV-' + theme + '.pdf',
|
||||||
html2canvas: { scale: 4, useCORS: true },
|
image: { type: 'jpeg', quality: 0.98 },
|
||||||
jsPDF: { format: 'a4', orientation: 'portrait' }
|
html2canvas: { scale: 4, useCORS: true },
|
||||||
};
|
jsPDF: { format: 'a4', orientation: 'portrait' },
|
||||||
html2pdf(areaCV, opt);
|
pagebreak: { mode: 'css', avoid: ['.experience_content', '.education_content', '.section-title'] }
|
||||||
} else {
|
};
|
||||||
// html2pdf.js options
|
|
||||||
let opt = {
|
return html2pdf().set(opt).from(areaCV).toContainer().then(function () {
|
||||||
margin: 0,
|
// Stretch the copy being rendered to a whole number of pages, so the
|
||||||
filename: 'myResumeCV-light.pdf',
|
// left column background reaches the bottom of the last page.
|
||||||
image: { type: 'jpeg', quality: 0.98 },
|
// 1px less avoids a blank extra page from rounding.
|
||||||
html2canvas: { scale: 4, useCORS: true },
|
let pageHeight = this.prop.pageSize.inner.px.height;
|
||||||
jsPDF: { format: 'a4', orientation: 'portrait' }
|
let resume = this.prop.container.firstElementChild;
|
||||||
};
|
let pages = Math.ceil(resume.offsetHeight / pageHeight);
|
||||||
html2pdf(areaCV, opt);
|
resume.style.minHeight = (Math.floor(pages * pageHeight) - 1) + 'px';
|
||||||
}
|
}).save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action executed by clicking on the button => generation of the final PDF CV CV
|
// Action executed by clicking on the button => generation of the final PDF CV CV
|
||||||
resumeButton.addEventListener("click", () => {
|
resumeButton.addEventListener("click", () => {
|
||||||
// Adapt the area of the PDF
|
// Adapt the area of the PDF
|
||||||
addScaleCV();
|
addScaleCV();
|
||||||
// Generate the PDF
|
// Generate the PDF, then remove the adaptation once it is saved
|
||||||
generateResume();
|
generateResume().finally(removeScaleCV);
|
||||||
// Remove adaptation after 1 second (you can choose to set more than 1 second if your PDF download time is long)
|
|
||||||
setTimeout(removeScaleCV, 1000);
|
|
||||||
});
|
});
|
||||||
@@ -123,7 +123,20 @@ body.scale-cv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.scale-cv .resume {
|
.scale-cv .resume {
|
||||||
height: 1122px;
|
/* At least one A4 page; grows so html2pdf can split it onto more pages */
|
||||||
|
min-height: 1122px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep entries and section titles together when breaking to a new page */
|
||||||
|
.scale-cv .experience_content,
|
||||||
|
.scale-cv .education_content,
|
||||||
|
.scale-cv .section-title {
|
||||||
|
break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Put <div class="page-break"></div> in the template to start a new PDF page there */
|
||||||
|
.page-break {
|
||||||
|
break-before: page;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scale-cv .resume_left {
|
.scale-cv .resume_left {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"birth": "14, November, 2000",
|
"birth": "14, November, 2000",
|
||||||
"living_location": "Ljubljana, Slovenia",
|
"living_location": "Ljubljana, Slovenia",
|
||||||
"web_link": "https://petrovv.com",
|
"web_link": "https://petrovv.com",
|
||||||
"git_link": "https://git.petrovv.com/explore",
|
"git_link": "https://git.petrovv.com",
|
||||||
"email": "nikola@petrovv.com",
|
"email": "nikola@petrovv.com",
|
||||||
"instagram_handle": "@nikolainsta7",
|
"instagram_handle": "@nikolainsta7",
|
||||||
"instagram_link": "https://www.instagram.com/nikolainsta7",
|
"instagram_link": "https://www.instagram.com/nikolainsta7",
|
||||||
|
|||||||
@@ -216,6 +216,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<div class="page-break"></div>
|
||||||
|
|
||||||
<!-- EDUCATION -->
|
<!-- EDUCATION -->
|
||||||
<section class="education section" id="education">
|
<section class="education section" id="education">
|
||||||
<h2 class="section-title">Education</h2>
|
<h2 class="section-title">Education</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user