1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function applyPDFStyles() {
const style = document.createElement('style');
style.textContent = `
@media print {
html, body {
height: auto !important;
overflow: visible !important;
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
}
/* Force certificates section to start on a new page */
#certificates {
page-break-before: always !important;
}
/* Allow breaks between sections */
section {
page-break-before: auto !important;
page-break-inside: auto !important;
margin-bottom: 20px !important; /* Add space between sections */
}
/* Keep section headers with at least some content */
section h2 {
page-break-after: avoid !important;
margin-bottom: 10px !important;
}
/* Allow breaks within lists, but keep list items together */
section > ul {
page-break-inside: auto !important;
margin-bottom: 15px !important;
}
section > ul > li {
page-break-inside: avoid !important;
margin-bottom: 15px !important;
}
/* Specific handling for projects and certificates */
#projects > ul > li,
#certificates > ul > li {
page-break-inside: auto !important;
margin-bottom: 20px !important;
}
/* Keep title and date together */
.title-period {
page-break-inside: avoid !important;
margin-bottom: 5px !important;
}
/* Allow breaks within highlights if necessary */
.highlights {
page-break-inside: auto !important;
}
.highlight-item {
page-break-inside: avoid !important;
margin-bottom: 8px !important;
}
/* Ensure no content is hidden by margins */
@page {
margin: 10mm 10mm; /* Top/bottom margin: 15mm, Left/right margin: 10mm */
}
/* Add some padding to the body for better content positioning */
body {
padding: 10mm 5mm;
}
}
`;
document.head.appendChild(style);
return style;
}
export function saveAsPDF() {
const saveButton = document.getElementById('saveAsPDFButton');
if (saveButton) {
saveButton.style.display = 'none';
}
const pdfStyle = applyPDFStyles();
// Capture the entire document
const element = document.documentElement;
const opt = {
margin: [8, 8, 8, 8], // top, right, bottom, left in mm
filename: 'resume.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {
scale: 3,
useCORS: true,
logging: true,
scrollY: -window.scrollY,
windowHeight: document.documentElement.offsetHeight
},
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },