ABDALLALSWAITI commited on
Commit
58e6b77
·
1 Parent(s): b1dd1e0

fix readme

Browse files
Files changed (2) hide show
  1. README.md +6 -8
  2. document.html +412 -0
README.md CHANGED
@@ -35,9 +35,7 @@ This guide covers the **optimized HTML to PDF conversion system** based on 2024-
35
 
36
  ### Example 1: Auto-Detection (Recommended)
37
  ```bash
38
- curl -X POST http://localhost:7860/convert \
39
- -F "html_file=@document.html" \
40
- -F "auto_detect=true" \
41
  -o output.pdf
42
  ```
43
 
@@ -49,7 +47,7 @@ The system will:
49
 
50
  ### Example 2: Force Multi-Page Document
51
  ```bash
52
- curl -X POST http://localhost:7860/convert \
53
  -F "html_file=@report.html" \
54
  -F "aspect_ratio=9:16" \
55
  -F "mode=multi" \
@@ -58,7 +56,7 @@ curl -X POST http://localhost:7860/convert \
58
 
59
  ### Example 3: Single-Page Infographic
60
  ```bash
61
- curl -X POST http://localhost:7860/convert \
62
  -F "html_file=@infographic.html" \
63
  -F "aspect_ratio=1:1" \
64
  -F "mode=single" \
@@ -67,7 +65,7 @@ curl -X POST http://localhost:7860/convert \
67
 
68
  ### Example 4: Presentation Slides
69
  ```bash
70
- curl -X POST http://localhost:7860/convert \
71
  -F "html_file=@presentation.html" \
72
  -F "aspect_ratio=16:9" \
73
  -F "mode=multi" \
@@ -76,7 +74,7 @@ curl -X POST http://localhost:7860/convert \
76
 
77
  ### Example 5: With Images
78
  ```bash
79
- curl -X POST http://localhost:7860/convert \
80
  -F "html_file=@document.html" \
81
  -F "images=@logo.png" \
82
  -F "images=@chart.jpg" \
@@ -517,4 +515,4 @@ waitUntil: 'networkidle2' // Instead of networkidle0
517
 
518
  **Version**: 2.0.0
519
  **Last Updated**: October 2025
520
- **Compatibility**: Puppeteer 23.x, Node.js 20.x
 
35
 
36
  ### Example 1: Auto-Detection (Recommended)
37
  ```bash
38
+ curl -X POST https://abdallalswaiti-htmlpdfs.hf.space/convert \
 
 
39
  -o output.pdf
40
  ```
41
 
 
47
 
48
  ### Example 2: Force Multi-Page Document
49
  ```bash
50
+ curl -X POST https://abdallalswaiti-htmlpdfs.hf.space/convert \
51
  -F "html_file=@report.html" \
52
  -F "aspect_ratio=9:16" \
53
  -F "mode=multi" \
 
56
 
57
  ### Example 3: Single-Page Infographic
58
  ```bash
59
+ curl -X POST https://abdallalswaiti-htmlpdfs.hf.space/convert \
60
  -F "html_file=@infographic.html" \
61
  -F "aspect_ratio=1:1" \
62
  -F "mode=single" \
 
65
 
66
  ### Example 4: Presentation Slides
67
  ```bash
68
+ curl -X POST https://abdallalswaiti-htmlpdfs.hf.space/convert \
69
  -F "html_file=@presentation.html" \
70
  -F "aspect_ratio=16:9" \
71
  -F "mode=multi" \
 
74
 
75
  ### Example 5: With Images
76
  ```bash
77
+ curl -X POST https://abdallalswaiti-htmlpdfs.hf.space/convert \
78
  -F "html_file=@document.html" \
79
  -F "images=@logo.png" \
80
  -F "images=@chart.jpg" \
 
515
 
516
  **Version**: 2.0.0
517
  **Last Updated**: October 2025
518
+ **Compatibility**: Puppeteer 23.x, Node.js 20.x
document.html ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Multi-Page PDF Example</title>
7
+ <style>
8
+ /* General document styling */
9
+ body {
10
+ font-family: 'Arial', sans-serif;
11
+ line-height: 1.6;
12
+ color: #333;
13
+ margin: 0;
14
+ padding: 40px;
15
+ background: white;
16
+ }
17
+
18
+ /* Page setup for printing */
19
+ @media print {
20
+ @page {
21
+ size: A4 portrait;
22
+ margin: 20mm;
23
+ }
24
+
25
+ body {
26
+ padding: 0;
27
+ }
28
+ }
29
+
30
+ /* Page containers - each will be a new page */
31
+ .page {
32
+ min-height: 100vh;
33
+ padding: 40px;
34
+ page-break-after: always;
35
+ break-after: page;
36
+ }
37
+
38
+ .page:last-child {
39
+ page-break-after: auto;
40
+ }
41
+
42
+ /* Header styles */
43
+ h1 {
44
+ color: #2563eb;
45
+ font-size: 2.5em;
46
+ margin-bottom: 10px;
47
+ page-break-after: avoid;
48
+ }
49
+
50
+ h2 {
51
+ color: #1e40af;
52
+ font-size: 2em;
53
+ margin-top: 30px;
54
+ margin-bottom: 15px;
55
+ page-break-after: avoid;
56
+ }
57
+
58
+ h3 {
59
+ color: #3b82f6;
60
+ font-size: 1.5em;
61
+ margin-top: 20px;
62
+ margin-bottom: 10px;
63
+ }
64
+
65
+ /* Paragraph styles */
66
+ p {
67
+ margin: 15px 0;
68
+ text-align: justify;
69
+ }
70
+
71
+ /* Box styling */
72
+ .info-box {
73
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
74
+ color: white;
75
+ padding: 30px;
76
+ border-radius: 10px;
77
+ margin: 20px 0;
78
+ page-break-inside: avoid;
79
+ }
80
+
81
+ .warning-box {
82
+ background: #fef3c7;
83
+ border-left: 4px solid #f59e0b;
84
+ padding: 20px;
85
+ margin: 20px 0;
86
+ page-break-inside: avoid;
87
+ }
88
+
89
+ /* Table styles */
90
+ table {
91
+ width: 100%;
92
+ border-collapse: collapse;
93
+ margin: 20px 0;
94
+ page-break-inside: auto;
95
+ }
96
+
97
+ thead {
98
+ background: #2563eb;
99
+ color: white;
100
+ display: table-header-group; /* Repeat on every page */
101
+ break-inside: avoid;
102
+ }
103
+
104
+ th, td {
105
+ padding: 12px;
106
+ text-align: left;
107
+ border: 1px solid #ddd;
108
+ }
109
+
110
+ tr {
111
+ page-break-inside: avoid;
112
+ page-break-after: auto;
113
+ }
114
+
115
+ tbody tr:nth-child(even) {
116
+ background: #f3f4f6;
117
+ }
118
+
119
+ /* List styles */
120
+ ul, ol {
121
+ margin: 15px 0;
122
+ padding-left: 30px;
123
+ }
124
+
125
+ li {
126
+ margin: 8px 0;
127
+ }
128
+
129
+ /* Code block */
130
+ pre {
131
+ background: #1f2937;
132
+ color: #f9fafb;
133
+ padding: 20px;
134
+ border-radius: 8px;
135
+ overflow-x: auto;
136
+ page-break-inside: avoid;
137
+ }
138
+
139
+ code {
140
+ font-family: 'Courier New', monospace;
141
+ font-size: 0.9em;
142
+ }
143
+
144
+ /* Footer */
145
+ .footer {
146
+ text-align: center;
147
+ color: #6b7280;
148
+ font-size: 0.9em;
149
+ margin-top: 40px;
150
+ padding-top: 20px;
151
+ border-top: 2px solid #e5e7eb;
152
+ }
153
+
154
+ /* Special elements */
155
+ .keep-together {
156
+ page-break-inside: avoid;
157
+ break-inside: avoid;
158
+ }
159
+
160
+ .signature {
161
+ margin-top: 60px;
162
+ border-top: 1px solid #333;
163
+ padding-top: 10px;
164
+ width: 200px;
165
+ }
166
+ </style>
167
+ </head>
168
+ <body>
169
+ <!-- Page 1: Title Page -->
170
+ <div class="page">
171
+ <div style="text-align: center; margin-top: 200px;">
172
+ <h1 style="font-size: 3em; margin-bottom: 20px;">Annual Report 2024</h1>
173
+ <p style="font-size: 1.5em; color: #6b7280;">Company Performance Overview</p>
174
+ <div style="margin-top: 100px;">
175
+ <p><strong>Prepared by:</strong> Analytics Department</p>
176
+ <p><strong>Date:</strong> October 17, 2025</p>
177
+ <p><strong>Document Type:</strong> Multi-Page PDF Demo</p>
178
+ </div>
179
+ </div>
180
+ </div>
181
+
182
+ <!-- Page 2: Executive Summary -->
183
+ <div class="page">
184
+ <h1>Executive Summary</h1>
185
+
186
+ <div class="info-box">
187
+ <h3 style="color: white; margin-top: 0;">Key Highlights</h3>
188
+ <p style="color: white;">This document demonstrates advanced PDF generation capabilities including multi-page support, proper page breaks, and professional formatting.</p>
189
+ </div>
190
+
191
+ <h2>Overview</h2>
192
+ <p>
193
+ This example document showcases the advanced capabilities of modern HTML to PDF conversion
194
+ using Puppeteer. The system intelligently handles page breaks, maintains formatting across
195
+ pages, and ensures that related content stays together.
196
+ </p>
197
+
198
+ <p>
199
+ The PDF generation engine supports multiple aspect ratios (16:9 for presentations, 1:1 for
200
+ social media, and 9:16 for documents), automatic mode detection, and sophisticated CSS
201
+ page break controls.
202
+ </p>
203
+
204
+ <h2>Features Demonstrated</h2>
205
+ <ul>
206
+ <li><strong>Multi-page support</strong> with natural page breaks</li>
207
+ <li><strong>Page break control</strong> using CSS properties</li>
208
+ <li><strong>Table header repetition</strong> across pages</li>
209
+ <li><strong>Keep-together elements</strong> to prevent awkward splits</li>
210
+ <li><strong>Professional formatting</strong> with consistent styling</li>
211
+ <li><strong>Print-optimized CSS</strong> for perfect rendering</li>
212
+ </ul>
213
+
214
+ <div class="warning-box">
215
+ <strong>⚠️ Important Note:</strong> This document uses CSS page break properties to control
216
+ how content flows across pages. Modern browsers and PDF generators respect these properties
217
+ when properly configured.
218
+ </div>
219
+ </div>
220
+
221
+ <!-- Page 3: Data Table -->
222
+ <div class="page">
223
+ <h1>Quarterly Performance Data</h1>
224
+
225
+ <p>
226
+ The following table demonstrates how table headers automatically repeat on each page when
227
+ the table spans multiple pages. This is achieved using the <code>display: table-header-group</code>
228
+ CSS property on the <code>&lt;thead&gt;</code> element.
229
+ </p>
230
+
231
+ <table>
232
+ <thead>
233
+ <tr>
234
+ <th>Quarter</th>
235
+ <th>Revenue</th>
236
+ <th>Growth</th>
237
+ <th>Status</th>
238
+ </tr>
239
+ </thead>
240
+ <tbody>
241
+ <tr>
242
+ <td>Q1 2024</td>
243
+ <td>$2,450,000</td>
244
+ <td>+12.5%</td>
245
+ <td>✓ Target Met</td>
246
+ </tr>
247
+ <tr>
248
+ <td>Q2 2024</td>
249
+ <td>$2,780,000</td>
250
+ <td>+13.5%</td>
251
+ <td>✓ Target Met</td>
252
+ </tr>
253
+ <tr>
254
+ <td>Q3 2024</td>
255
+ <td>$3,120,000</td>
256
+ <td>+12.2%</td>
257
+ <td>✓ Target Met</td>
258
+ </tr>
259
+ <tr>
260
+ <td>Q4 2024</td>
261
+ <td>$3,650,000</td>
262
+ <td>+17.0%</td>
263
+ <td>✓ Exceeded</td>
264
+ </tr>
265
+ </tbody>
266
+ </table>
267
+
268
+ <h2>Regional Performance</h2>
269
+ <table>
270
+ <thead>
271
+ <tr>
272
+ <th>Region</th>
273
+ <th>Sales</th>
274
+ <th>Market Share</th>
275
+ <th>Year-over-Year</th>
276
+ </tr>
277
+ </thead>
278
+ <tbody>
279
+ <tr>
280
+ <td>North America</td>
281
+ <td>$8,500,000</td>
282
+ <td>42%</td>
283
+ <td>+15%</td>
284
+ </tr>
285
+ <tr>
286
+ <td>Europe</td>
287
+ <td>$6,200,000</td>
288
+ <td>31%</td>
289
+ <td>+18%</td>
290
+ </tr>
291
+ <tr>
292
+ <td>Asia Pacific</td>
293
+ <td>$4,100,000</td>
294
+ <td>20%</td>
295
+ <td>+22%</td>
296
+ </tr>
297
+ <tr>
298
+ <td>Latin America</td>
299
+ <td>$1,400,000</td>
300
+ <td>7%</td>
301
+ <td>+9%</td>
302
+ </tr>
303
+ </tbody>
304
+ </table>
305
+ </div>
306
+
307
+ <!-- Page 4: Technical Implementation -->
308
+ <div class="page">
309
+ <h1>Technical Implementation</h1>
310
+
311
+ <h2>CSS Best Practices for PDF Generation</h2>
312
+
313
+ <p>
314
+ Proper PDF generation requires careful consideration of CSS page break properties.
315
+ Here are the key techniques used in this document:
316
+ </p>
317
+
318
+ <div class="keep-together">
319
+ <h3>Page Break Control</h3>
320
+ <pre><code>/* Force a page break after this element */
321
+ .page {
322
+ page-break-after: always;
323
+ break-after: page;
324
+ }
325
+
326
+ /* Prevent breaks inside an element */
327
+ .keep-together {
328
+ page-break-inside: avoid;
329
+ break-inside: avoid;
330
+ }
331
+
332
+ /* Avoid breaks after headings */
333
+ h1, h2, h3 {
334
+ page-break-after: avoid;
335
+ }</code></pre>
336
+ </div>
337
+
338
+ <div class="keep-together">
339
+ <h3>Table Header Repetition</h3>
340
+ <pre><code>/* Make table headers repeat on each page */
341
+ thead {
342
+ display: table-header-group;
343
+ break-inside: avoid;
344
+ }
345
+
346
+ /* Prevent table rows from breaking */
347
+ tr {
348
+ page-break-inside: avoid;
349
+ }</code></pre>
350
+ </div>
351
+
352
+ <h2>Key Configuration Options</h2>
353
+ <ul>
354
+ <li><strong>preferCSSPageSize: true</strong> - Respects CSS @page rules</li>
355
+ <li><strong>printBackground: true</strong> - Includes background colors and images</li>
356
+ <li><strong>emulateMediaType('print')</strong> - Uses print CSS media queries</li>
357
+ <li><strong>format: 'A4'</strong> - Standard paper size for documents</li>
358
+ </ul>
359
+ </div>
360
+
361
+ <!-- Page 5: Conclusion -->
362
+ <div class="page">
363
+ <h1>Conclusion</h1>
364
+
365
+ <p>
366
+ This document has demonstrated the comprehensive capabilities of modern HTML to PDF
367
+ conversion using Puppeteer with proper page break handling and professional formatting.
368
+ </p>
369
+
370
+ <h2>Summary of Capabilities</h2>
371
+
372
+ <div class="keep-together">
373
+ <h3>Multi-Page Support</h3>
374
+ <p>
375
+ The system automatically handles documents of any length, properly breaking content
376
+ across pages while respecting CSS page break properties. Content stays together when
377
+ needed, and breaks naturally when appropriate.
378
+ </p>
379
+ </div>
380
+
381
+ <div class="keep-together">
382
+ <h3>Professional Formatting</h3>
383
+ <p>
384
+ All styling, including backgrounds, colors, fonts, and layouts, is preserved in the
385
+ final PDF. The output is print-ready and maintains professional appearance across
386
+ all pages.
387
+ </p>
388
+ </div>
389
+
390
+ <div class="keep-together">
391
+ <h3>Flexible Configuration</h3>
392
+ <p>
393
+ Support for multiple aspect ratios, automatic mode detection, and extensive CSS
394
+ control makes this solution suitable for any document type, from reports and invoices
395
+ to presentations and infographics.
396
+ </p>
397
+ </div>
398
+
399
+ <div class="footer">
400
+ <p>End of Document</p>
401
+ <p>Generated with Advanced HTML to PDF API v2.0</p>
402
+ <p>© 2024-2025 | All Rights Reserved</p>
403
+ </div>
404
+
405
+ <div class="signature">
406
+ <p><strong>Approved By:</strong></p>
407
+ <p>_______________________</p>
408
+ <p style="font-size: 0.9em; margin-top: 5px;">Director of Operations</p>
409
+ </div>
410
+ </div>
411
+ </body>
412
+ </html>