Spaces:
Sleeping
Sleeping
File size: 12,420 Bytes
58e6b77 |
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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi-Page PDF Example</title>
<style>
/* General document styling */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 40px;
background: white;
}
/* Page setup for printing */
@media print {
@page {
size: A4 portrait;
margin: 20mm;
}
body {
padding: 0;
}
}
/* Page containers - each will be a new page */
.page {
min-height: 100vh;
padding: 40px;
page-break-after: always;
break-after: page;
}
.page:last-child {
page-break-after: auto;
}
/* Header styles */
h1 {
color: #2563eb;
font-size: 2.5em;
margin-bottom: 10px;
page-break-after: avoid;
}
h2 {
color: #1e40af;
font-size: 2em;
margin-top: 30px;
margin-bottom: 15px;
page-break-after: avoid;
}
h3 {
color: #3b82f6;
font-size: 1.5em;
margin-top: 20px;
margin-bottom: 10px;
}
/* Paragraph styles */
p {
margin: 15px 0;
text-align: justify;
}
/* Box styling */
.info-box {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 10px;
margin: 20px 0;
page-break-inside: avoid;
}
.warning-box {
background: #fef3c7;
border-left: 4px solid #f59e0b;
padding: 20px;
margin: 20px 0;
page-break-inside: avoid;
}
/* Table styles */
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
page-break-inside: auto;
}
thead {
background: #2563eb;
color: white;
display: table-header-group; /* Repeat on every page */
break-inside: avoid;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}
tr {
page-break-inside: avoid;
page-break-after: auto;
}
tbody tr:nth-child(even) {
background: #f3f4f6;
}
/* List styles */
ul, ol {
margin: 15px 0;
padding-left: 30px;
}
li {
margin: 8px 0;
}
/* Code block */
pre {
background: #1f2937;
color: #f9fafb;
padding: 20px;
border-radius: 8px;
overflow-x: auto;
page-break-inside: avoid;
}
code {
font-family: 'Courier New', monospace;
font-size: 0.9em;
}
/* Footer */
.footer {
text-align: center;
color: #6b7280;
font-size: 0.9em;
margin-top: 40px;
padding-top: 20px;
border-top: 2px solid #e5e7eb;
}
/* Special elements */
.keep-together {
page-break-inside: avoid;
break-inside: avoid;
}
.signature {
margin-top: 60px;
border-top: 1px solid #333;
padding-top: 10px;
width: 200px;
}
</style>
</head>
<body>
<!-- Page 1: Title Page -->
<div class="page">
<div style="text-align: center; margin-top: 200px;">
<h1 style="font-size: 3em; margin-bottom: 20px;">Annual Report 2024</h1>
<p style="font-size: 1.5em; color: #6b7280;">Company Performance Overview</p>
<div style="margin-top: 100px;">
<p><strong>Prepared by:</strong> Analytics Department</p>
<p><strong>Date:</strong> October 17, 2025</p>
<p><strong>Document Type:</strong> Multi-Page PDF Demo</p>
</div>
</div>
</div>
<!-- Page 2: Executive Summary -->
<div class="page">
<h1>Executive Summary</h1>
<div class="info-box">
<h3 style="color: white; margin-top: 0;">Key Highlights</h3>
<p style="color: white;">This document demonstrates advanced PDF generation capabilities including multi-page support, proper page breaks, and professional formatting.</p>
</div>
<h2>Overview</h2>
<p>
This example document showcases the advanced capabilities of modern HTML to PDF conversion
using Puppeteer. The system intelligently handles page breaks, maintains formatting across
pages, and ensures that related content stays together.
</p>
<p>
The PDF generation engine supports multiple aspect ratios (16:9 for presentations, 1:1 for
social media, and 9:16 for documents), automatic mode detection, and sophisticated CSS
page break controls.
</p>
<h2>Features Demonstrated</h2>
<ul>
<li><strong>Multi-page support</strong> with natural page breaks</li>
<li><strong>Page break control</strong> using CSS properties</li>
<li><strong>Table header repetition</strong> across pages</li>
<li><strong>Keep-together elements</strong> to prevent awkward splits</li>
<li><strong>Professional formatting</strong> with consistent styling</li>
<li><strong>Print-optimized CSS</strong> for perfect rendering</li>
</ul>
<div class="warning-box">
<strong>⚠️ Important Note:</strong> This document uses CSS page break properties to control
how content flows across pages. Modern browsers and PDF generators respect these properties
when properly configured.
</div>
</div>
<!-- Page 3: Data Table -->
<div class="page">
<h1>Quarterly Performance Data</h1>
<p>
The following table demonstrates how table headers automatically repeat on each page when
the table spans multiple pages. This is achieved using the <code>display: table-header-group</code>
CSS property on the <code><thead></code> element.
</p>
<table>
<thead>
<tr>
<th>Quarter</th>
<th>Revenue</th>
<th>Growth</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q1 2024</td>
<td>$2,450,000</td>
<td>+12.5%</td>
<td>✓ Target Met</td>
</tr>
<tr>
<td>Q2 2024</td>
<td>$2,780,000</td>
<td>+13.5%</td>
<td>✓ Target Met</td>
</tr>
<tr>
<td>Q3 2024</td>
<td>$3,120,000</td>
<td>+12.2%</td>
<td>✓ Target Met</td>
</tr>
<tr>
<td>Q4 2024</td>
<td>$3,650,000</td>
<td>+17.0%</td>
<td>✓ Exceeded</td>
</tr>
</tbody>
</table>
<h2>Regional Performance</h2>
<table>
<thead>
<tr>
<th>Region</th>
<th>Sales</th>
<th>Market Share</th>
<th>Year-over-Year</th>
</tr>
</thead>
<tbody>
<tr>
<td>North America</td>
<td>$8,500,000</td>
<td>42%</td>
<td>+15%</td>
</tr>
<tr>
<td>Europe</td>
<td>$6,200,000</td>
<td>31%</td>
<td>+18%</td>
</tr>
<tr>
<td>Asia Pacific</td>
<td>$4,100,000</td>
<td>20%</td>
<td>+22%</td>
</tr>
<tr>
<td>Latin America</td>
<td>$1,400,000</td>
<td>7%</td>
<td>+9%</td>
</tr>
</tbody>
</table>
</div>
<!-- Page 4: Technical Implementation -->
<div class="page">
<h1>Technical Implementation</h1>
<h2>CSS Best Practices for PDF Generation</h2>
<p>
Proper PDF generation requires careful consideration of CSS page break properties.
Here are the key techniques used in this document:
</p>
<div class="keep-together">
<h3>Page Break Control</h3>
<pre><code>/* Force a page break after this element */
.page {
page-break-after: always;
break-after: page;
}
/* Prevent breaks inside an element */
.keep-together {
page-break-inside: avoid;
break-inside: avoid;
}
/* Avoid breaks after headings */
h1, h2, h3 {
page-break-after: avoid;
}</code></pre>
</div>
<div class="keep-together">
<h3>Table Header Repetition</h3>
<pre><code>/* Make table headers repeat on each page */
thead {
display: table-header-group;
break-inside: avoid;
}
/* Prevent table rows from breaking */
tr {
page-break-inside: avoid;
}</code></pre>
</div>
<h2>Key Configuration Options</h2>
<ul>
<li><strong>preferCSSPageSize: true</strong> - Respects CSS @page rules</li>
<li><strong>printBackground: true</strong> - Includes background colors and images</li>
<li><strong>emulateMediaType('print')</strong> - Uses print CSS media queries</li>
<li><strong>format: 'A4'</strong> - Standard paper size for documents</li>
</ul>
</div>
<!-- Page 5: Conclusion -->
<div class="page">
<h1>Conclusion</h1>
<p>
This document has demonstrated the comprehensive capabilities of modern HTML to PDF
conversion using Puppeteer with proper page break handling and professional formatting.
</p>
<h2>Summary of Capabilities</h2>
<div class="keep-together">
<h3>Multi-Page Support</h3>
<p>
The system automatically handles documents of any length, properly breaking content
across pages while respecting CSS page break properties. Content stays together when
needed, and breaks naturally when appropriate.
</p>
</div>
<div class="keep-together">
<h3>Professional Formatting</h3>
<p>
All styling, including backgrounds, colors, fonts, and layouts, is preserved in the
final PDF. The output is print-ready and maintains professional appearance across
all pages.
</p>
</div>
<div class="keep-together">
<h3>Flexible Configuration</h3>
<p>
Support for multiple aspect ratios, automatic mode detection, and extensive CSS
control makes this solution suitable for any document type, from reports and invoices
to presentations and infographics.
</p>
</div>
<div class="footer">
<p>End of Document</p>
<p>Generated with Advanced HTML to PDF API v2.0</p>
<p>© 2024-2025 | All Rights Reserved</p>
</div>
<div class="signature">
<p><strong>Approved By:</strong></p>
<p>_______________________</p>
<p style="font-size: 0.9em; margin-top: 5px;">Director of Operations</p>
</div>
</div>
</body>
</html>
|