-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_pdf.js
More file actions
196 lines (171 loc) · 5.63 KB
/
Copy pathgenerate_pdf.js
File metadata and controls
196 lines (171 loc) · 5.63 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import puppeteer from 'puppeteer';
(async () => {
console.log("Launching browser...");
const browser = await puppeteer.launch({
headless: "new",
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
// Set viewport to desktop size
await page.setViewport({ width: 1280, height: 1024 });
console.log("Navigating to page...");
// Navigate to local dev server
await page.goto('http://localhost:3000', { waitUntil: 'networkidle0', timeout: 60000 });
console.log("Scrolling to trigger lazy loaded images...");
await page.evaluate(async () => {
await new Promise((resolve) => {
let totalHeight = 0;
const distance = 100;
const timer = setInterval(() => {
const scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 50);
});
window.scrollTo(0, 0);
});
await new Promise(r => setTimeout(r, 2000));
console.log("Injecting PDF print styles...");
const documentStyles = `
/* === ESSENTIAL PDF RESETS === */
* {
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
content-visibility: visible !important;
contain-intrinsic-size: auto !important;
}
/* Hide Navigation/UI */
header, aside, button, .mobile-index-trigger, .scroll-to-top, .theme-toggle, .risk-reward-chart-container {
display: none !important;
}
.fixed { display: none !important; }
/* === LAYOUT FIXES === */
body {
background-color: #ffffff !important;
font-size: 12pt !important;
line-height: 1.5 !important;
overflow: visible !important;
height: auto !important;
color: #000000 !important;
}
main {
padding: 0 !important;
max-width: 100% !important;
margin: 0 !important;
}
section {
margin-bottom: 40px !important;
page-break-inside: auto;
}
/* FORCE DESKTOP LAYOUT (Preserve side-by-side for images) */
@media print {
.lg\\:flex-row {
flex-direction: row !important;
}
.lg\\:w-1\\/3 {
width: 33.333333% !important;
}
.lg\\:w-5\\/12 {
width: 41.666667% !important;
}
.flex-1 {
flex: 1 1 0% !important;
}
img {
break-inside: avoid;
page-break-inside: avoid;
}
}
/* === FONT SIZES === */
h2 { font-size: 15pt !important; }
h3 { font-size: 14pt !important; }
h4, strong, .font-serif.text-lg { font-size: 13pt !important; }
p, li, span, div, td { font-size: 12pt !important; line-height: 1.5 !important; }
p span { font-size: inherit !important; }
/* === SUPER AGGRESSIVE DE-MARKING === */
/* 1. Target the Gradient Title explicitly and destroy it */
h2.text-transparent.bg-clip-text,
.text-transparent,
.bg-clip-text {
color: #000000 !important;
background: none !important;
background-image: none !important;
-webkit-text-fill-color: #000000 !important;
text-shadow: none !important;
}
/* 2. Target the Gold Pill explicitly and neutralize it */
.text-premium-gold {
color: #000000 !important;
-webkit-text-fill-color: #000000 !important;
}
.border-premium-gold, .border-premium-gold\\/30 {
border-color: #000000 !important;
}
/* 3. Global Color Force */
h1, h2, h3, h4, h5, h6,
p, li, span, div, strong, em, b, i, q {
color: #000000 !important;
}
/* 4. Fix Nota/Attenzione Boxes */
/* Often these are div with bg-gradient or borders */
.border-l-2 {
border-color: #000000 !important;
background: #ffffff !important;
}
div[class*="bg-gradient"] {
background: #ffffff !important;
}
/* Ensure the text inside them is black (covered by global but just in case) */
/* 5. Links - Black and Underlined */
a {
color: #000000 !important;
text-decoration: underline;
}
/* Tables */
table {
border-collapse: collapse;
width: 100%;
margin: 1em 0;
border: 1px solid #000000 !important;
}
th, td {
border: 1px solid #000000 !important;
padding: 0.5rem;
color: #000000 !important;
}
`;
// === LIGHT MODE GENERATION ONLY ===
console.log("Switching to Light Mode...");
await page.evaluate(() => {
document.documentElement.classList.remove('dark');
});
await page.evaluate((styles) => {
const styleEl = document.createElement('style');
styleEl.innerHTML = styles;
document.head.appendChild(styleEl);
}, documentStyles);
console.log("Generating website_light.pdf...");
await page.pdf({
path: 'website_light.pdf',
format: 'A4',
landscape: false,
printBackground: true,
margin: { top: '1.5cm', right: '1cm', bottom: '1.5cm', left: '1cm' },
displayHeaderFooter: true,
headerTemplate: `
<div style="font-size: 9px; margin-left: 1cm; width: 100%; display: flex; justify-content: space-between; font-family: sans-serif; color: #000;">
<span>Economia Aziendale</span>
<span style="margin-right: 1cm;">Author: Singh Rishapveer</span>
</div>`,
footerTemplate: `
<div style="font-size: 9px; margin-left: 1cm; margin-right: 1cm; width: 100%; text-align: center; color: #000; font-family: sans-serif;">
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
</div>`,
});
await browser.close();
console.log("Done.");
})();