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
 
 
 
 
 
 
 
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>HTML to PDF Converter</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
9
+ <style>
10
+ * {
11
+ margin: 0;
12
+ padding: 0;
13
+ box-sizing: border-box;
14
+ }
15
+ body {
16
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
17
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
18
+ min-height: 100vh;
19
+ padding: 20px;
20
+ }
21
+ .container {
22
+ max-width: 1400px;
23
+ margin: 0 auto;
24
+ }
25
+ .header {
26
+ text-align: center;
27
+ color: white;
28
+ margin-bottom: 30px;
29
+ }
30
+ .header h1 {
31
+ font-size: 36px;
32
+ margin-bottom: 10px;
33
+ }
34
+ .header p {
35
+ font-size: 16px;
36
+ opacity: 0.9;
37
+ }
38
+ .main-content {
39
+ display: grid;
40
+ grid-template-columns: 1fr 1fr;
41
+ gap: 20px;
42
+ margin-bottom: 20px;
43
+ }
44
+ .panel {
45
+ background: white;
46
+ border-radius: 10px;
47
+ padding: 20px;
48
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
49
+ }
50
+ .panel h2 {
51
+ color: #333;
52
+ margin-bottom: 15px;
53
+ font-size: 20px;
54
+ display: flex;
55
+ align-items: center;
56
+ gap: 10px;
57
+ }
58
+ textarea {
59
+ width: 100%;
60
+ height: 500px;
61
+ padding: 15px;
62
+ border: 2px solid #e2e8f0;
63
+ border-radius: 8px;
64
+ font-family: 'Courier New', monospace;
65
+ font-size: 14px;
66
+ resize: vertical;
67
+ transition: border-color 0.3s;
68
+ }
69
+ textarea:focus {
70
+ outline: none;
71
+ border-color: #667eea;
72
+ }
73
+ .preview-container {
74
+ width: 100%;
75
+ height: 500px;
76
+ border: 2px solid #e2e8f0;
77
+ border-radius: 8px;
78
+ overflow: auto;
79
+ background: white;
80
+ }
81
+ #preview {
82
+ padding: 20px;
83
+ background: white;
84
+ }
85
+ .controls {
86
+ background: white;
87
+ padding: 20px;
88
+ border-radius: 10px;
89
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
90
+ display: flex;
91
+ gap: 15px;
92
+ flex-wrap: wrap;
93
+ justify-content: center;
94
+ }
95
+ button {
96
+ padding: 14px 28px;
97
+ border: none;
98
+ border-radius: 8px;
99
+ font-size: 16px;
100
+ cursor: pointer;
101
+ transition: all 0.3s;
102
+ font-weight: 600;
103
+ display: flex;
104
+ align-items: center;
105
+ gap: 8px;
106
+ }
107
+ button:disabled {
108
+ opacity: 0.5;
109
+ cursor: not-allowed;
110
+ }
111
+ .btn-preview {
112
+ background: #4299e1;
113
+ color: white;
114
+ }
115
+ .btn-preview:hover:not(:disabled) {
116
+ background: #3182ce;
117
+ transform: translateY(-2px);
118
+ box-shadow: 0 4px 12px rgba(66, 153, 225, 0.4);
119
+ }
120
+ .btn-download {
121
+ background: #48bb78;
122
+ color: white;
123
+ }
124
+ .btn-download:hover:not(:disabled) {
125
+ background: #38a169;
126
+ transform: translateY(-2px);
127
+ box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
128
+ }
129
+ .btn-open {
130
+ background: #ed8936;
131
+ color: white;
132
+ }
133
+ .btn-open:hover:not(:disabled) {
134
+ background: #dd6b20;
135
+ transform: translateY(-2px);
136
+ box-shadow: 0 4px 12px rgba(237, 137, 54, 0.4);
137
+ }
138
+ .btn-clear {
139
+ background: #f56565;
140
+ color: white;
141
+ }
142
+ .btn-clear:hover:not(:disabled) {
143
+ background: #e53e3e;
144
+ transform: translateY(-2px);
145
+ box-shadow: 0 4px 12px rgba(245, 101, 101, 0.4);
146
+ }
147
+ .example-btn {
148
+ background: #9f7aea;
149
+ color: white;
150
+ }
151
+ .example-btn:hover:not(:disabled) {
152
+ background: #805ad5;
153
+ transform: translateY(-2px);
154
+ box-shadow: 0 4px 12px rgba(159, 122, 234, 0.4);
155
+ }
156
+ @media (max-width: 1024px) {
157
+ .main-content {
158
+ grid-template-columns: 1fr;
159
+ }
160
+ }
161
+ .placeholder-text {
162
+ color: #a0aec0;
163
+ font-style: italic;
164
+ padding: 20px;
165
+ }
166
+ .loading {
167
+ position: fixed;
168
+ top: 0;
169
+ left: 0;
170
+ right: 0;
171
+ bottom: 0;
172
+ background: rgba(0,0,0,0.7);
173
+ display: none;
174
+ justify-content: center;
175
+ align-items: center;
176
+ z-index: 1000;
177
+ }
178
+ .loading.active {
179
+ display: flex;
180
+ }
181
+ .loading-content {
182
+ background: white;
183
+ padding: 30px;
184
+ border-radius: 10px;
185
+ text-align: center;
186
+ }
187
+ .spinner {
188
+ border: 4px solid #f3f3f3;
189
+ border-top: 4px solid #667eea;
190
+ border-radius: 50%;
191
+ width: 40px;
192
+ height: 40px;
193
+ animation: spin 1s linear infinite;
194
+ margin: 0 auto 15px;
195
+ }
196
+ @keyframes spin {
197
+ 0% { transform: rotate(0deg); }
198
+ 100% { transform: rotate(360deg); }
199
+ }
200
+ </style>
201
+ </head>
202
+ <body>
203
+ <div class="loading" id="loading">
204
+ <div class="loading-content">
205
+ <div class="spinner"></div>
206
+ <p>Generating PDF...</p>
207
+ </div>
208
+ </div>
209
+
210
+ <div class="container">
211
+ <div class="header">
212
+ <h1>📄 HTML to PDF Converter</h1>
213
+ <p>Paste your HTML code, preview it, and save as high-quality PDF</p>
214
+ </div>
215
+
216
+ <div class="main-content">
217
+ <div class="panel">
218
+ <h2>📝 HTML Code</h2>
219
+ <textarea id="htmlInput" placeholder="Paste your HTML code here..."></textarea>
220
+ </div>
221
+
222
+ <div class="panel">
223
+ <h2>👁️ Live Preview</h2>
224
+ <div class="preview-container">
225
+ <div id="preview">
226
+ <div class="placeholder-text">
227
+ Preview will appear here...
228
+ </div>
229
+ </div>
230
+ </div>
231
+ </div>
232
+ </div>
233
+
234
+ <div class="controls">
235
+ <button class="btn-preview" onclick="updatePreview()">
236
+ 🔄 Update Preview
237
+ </button>
238
+ <button class="btn-download" onclick="downloadPDF()">
239
+ ⬇️ Download as PDF
240
+ </button>
241
+ <button class="btn-open" onclick="openPDFNewTab()">
242
+ 🔗 Open PDF in New Tab
243
+ </button>
244
+ <button class="example-btn" onclick="loadExample()">
245
+ 📋 Load Example
246
+ </button>
247
+ <button class="btn-clear" onclick="clearAll()">
248
+ 🗑️ Clear All
249
+ </button>
250
+ </div>
251
+ </div>
252
+
253
+ <script>
254
+ const htmlInput = document.getElementById('htmlInput');
255
+ const preview = document.getElementById('preview');
256
+ const loading = document.getElementById('loading');
257
+
258
+ // Auto-update preview as user types (with debouncing)
259
+ let typingTimer;
260
+ htmlInput.addEventListener('input', function() {
261
+ clearTimeout(typingTimer);
262
+ typingTimer = setTimeout(updatePreview, 500);
263
+ });
264
+
265
+ // Update preview function
266
+ function updatePreview() {
267
+ const htmlCode = htmlInput.value;
268
+ if (htmlCode.trim() === '') {
269
+ preview.innerHTML = '<div class="placeholder-text">Preview will appear here...</div>';
270
+ } else {
271
+ preview.innerHTML = htmlCode;
272
+ }
273
+ }
274
+
275
+ // Show/hide loading
276
+ function showLoading() {
277
+ loading.classList.add('active');
278
+ }
279
+
280
+ function hideLoading() {
281
+ loading.classList.remove('active');
282
+ }
283
+
284
+ // Generate PDF using html2canvas and jsPDF
285
+ async function generatePDF(mode = 'download') {
286
+ if (htmlInput.value.trim() === '') {
287
+ alert('Please enter some HTML code first!');
288
+ return;
289
+ }
290
+
291
+ showLoading();
292
+
293
+ try {
294
+ // Use html2canvas to capture the preview
295
+ const canvas = await html2canvas(preview, {
296
+ scale: 3, // Higher quality
297
+ useCORS: true,
298
+ allowTaint: true,
299
+ backgroundColor: '#ffffff',
300
+ logging: false,
301
+ windowWidth: preview.scrollWidth,
302
+ windowHeight: preview.scrollHeight
303
+ });
304
+
305
+ const imgData = canvas.toDataURL('image/png');
306
+
307
+ // Calculate PDF dimensions
308
+ const imgWidth = 210; // A4 width in mm
309
+ const pageHeight = 297; // A4 height in mm
310
+ const imgHeight = (canvas.height * imgWidth) / canvas.width;
311
+ let heightLeft = imgHeight;
312
+
313
+ const { jsPDF } = window.jspdf;
314
+ const pdf = new jsPDF('p', 'mm', 'a4');
315
+ let position = 0;
316
+
317
+ // Add first page
318
+ pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
319
+ heightLeft -= pageHeight;
320
+
321
+ // Add additional pages if content is longer
322
+ while (heightLeft > 0) {
323
+ position = heightLeft - imgHeight;
324
+ pdf.addPage();
325
+ pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
326
+ heightLeft -= pageHeight;
327
+ }
328
+
329
+ if (mode === 'download') {
330
+ pdf.save('document.pdf');
331
+ } else if (mode === 'open') {
332
+ const pdfBlob = pdf.output('blob');
333
+ const pdfUrl = URL.createObjectURL(pdfBlob);
334
+ window.open(pdfUrl, '_blank');
335
+ }
336
+
337
+ } catch (error) {
338
+ console.error('Error generating PDF:', error);
339
+ alert('Error generating PDF. Please try again.');
340
+ } finally {
341
+ hideLoading();
342
+ }
343
+ }
344
+
345
+ // Download PDF
346
+ function downloadPDF() {
347
+ generatePDF('download');
348
+ }
349
+
350
+ // Open PDF in new tab
351
+ function openPDFNewTab() {
352
+ generatePDF('open');
353
+ }
354
+
355
+ // Clear all
356
+ function clearAll() {
357
+ htmlInput.value = '';
358
+ preview.innerHTML = '<div class="placeholder-text">Preview will appear here...</div>';
359
+ }
360
+
361
+ // Load example HTML
362
+ function loadExample() {
363
+ const exampleHTML = `<style>
364
+ body {
365
+ font-family: Arial, sans-serif;
366
+ max-width: 800px;
367
+ margin: 0 auto;
368
+ padding: 20px;
369
+ line-height: 1.6;
370
+ }
371
+ h1 {
372
+ color: #2c3e50;
373
+ border-bottom: 3px solid #3498db;
374
+ padding-bottom: 10px;
375
+ }
376
+ h2 {
377
+ color: #34495e;
378
+ margin-top: 25px;
379
+ }
380
+ .highlight {
381
+ background: #ffffcc;
382
+ padding: 15px;
383
+ border-left: 4px solid #f39c12;
384
+ margin: 20px 0;
385
+ }
386
+ table {
387
+ width: 100%;
388
+ border-collapse: collapse;
389
+ margin: 20px 0;
390
+ }
391
+ th {
392
+ background: #3498db;
393
+ color: white;
394
+ padding: 12px;
395
+ text-align: left;
396
+ }
397
+ td {
398
+ padding: 10px;
399
+ border-bottom: 1px solid #ddd;
400
+ }
401
+ tr:hover {
402
+ background: #f5f5f5;
403
+ }
404
+ .footer {
405
+ margin-top: 40px;
406
+ padding-top: 20px;
407
+ border-top: 2px solid #eee;
408
+ color: #7f8c8d;
409
+ font-size: 14px;
410
+ }
411
+ </style>
412
+
413
+ <h1>Sample Business Report</h1>
414
+
415
+ <div class="highlight">
416
+ <strong>Important:</strong> This is a sample document showing how all styles are preserved in the PDF output.
417
+ </div>
418
+
419
+ <h2>Company Overview</h2>
420
+ <p>This document demonstrates how HTML content with complete styling can be converted to PDF format without losing any design elements. All colors, fonts, spacing, and layouts are preserved exactly as designed.</p>
421
+
422
+ <h2>Quarterly Results</h2>
423
+ <table>
424
+ <thead>
425
+ <tr>
426
+ <th>Quarter</th>
427
+ <th>Revenue</th>
428
+ <th>Growth</th>
429
+ </tr>
430
+ </thead>
431
+ <tbody>
432
+ <tr>
433
+ <td>Q1 2024</td>
434
+ <td>$250,000</td>
435
+ <td>+15%</td>
436
+ </tr>
437
+ <tr>
438
+ <td>Q2 2024</td>
439
+ <td>$280,000</td>
440
+ <td>+12%</td>
441
+ </tr>
442
+ <tr>
443
+ <td>Q3 2024</td>
444
+ <td>$320,000</td>
445
+ <td>+14%</td>
446
+ </tr>
447
+ </tbody>
448
+ </table>
449
+
450
+ <h2>Key Achievements</h2>
451
+ <ul>
452
+ <li>Expanded to 5 new markets</li>
453
+ <li>Increased customer satisfaction by 25%</li>
454
+ <li>Launched 3 new product lines</li>
455
+ <li>Achieved record quarterly revenue</li>
456
+ </ul>
457
+
458
+ <div class="footer">
459
+ <p>Generated on ${new Date().toLocaleDateString()} | Confidential Document</p>
460
+ </div>`;
461
+ htmlInput.value = exampleHTML;
462
+ updatePreview();
463
+ }
464
+ </script>
465
+ </body>
466
+ </html>