JakeFake222 commited on
Commit
8ee53dc
·
verified ·
1 Parent(s): 7f8cd3d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +119 -19
index.html CHANGED
@@ -1,19 +1,119 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Images to PDF</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 20px;
11
+ text-align: center;
12
+ }
13
+ #imageContainer {
14
+ display: flex;
15
+ flex-wrap: nowrap;
16
+ overflow-x: auto;
17
+ gap: 10px;
18
+ margin: 20px 0;
19
+ padding: 10px;
20
+ border: 1px solid #ccc;
21
+ }
22
+ .imageWrapper {
23
+ flex: 0 0 auto;
24
+ max-width: 200px;
25
+ }
26
+ .imageWrapper img {
27
+ max-width: 100%;
28
+ height: auto;
29
+ border: 1px solid #ddd;
30
+ border-radius: 5px;
31
+ }
32
+ button {
33
+ padding: 10px 20px;
34
+ font-size: 16px;
35
+ cursor: pointer;
36
+ background-color: #4CAF50;
37
+ color: white;
38
+ border: none;
39
+ border-radius: 5px;
40
+ }
41
+ button:hover {
42
+ background-color: #45a049;
43
+ }
44
+ </style>
45
+ </head>
46
+ <body>
47
+ <h1>Images to PDF Converter</h1>
48
+ <input type="file" id="imageInput" accept="image/*" multiple>
49
+ <div id="imageContainer"></div>
50
+ <button onclick="generatePDF()">Download as PDF</button>
51
+
52
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
53
+ <script>
54
+ const { jsPDF } = window.jspdf;
55
+ const imageInput = document.getElementById('imageInput');
56
+ const imageContainer = document.getElementById('imageContainer');
57
+ let images = [];
58
+
59
+ // Handle image uploads
60
+ imageInput.addEventListener('change', (event) => {
61
+ images = [];
62
+ imageContainer.innerHTML = '';
63
+ const files = Array.from(event.target.files);
64
+
65
+ files.forEach((file) => {
66
+ const reader = new FileReader();
67
+ reader.onload = (e) => {
68
+ const img = new Image();
69
+ img.src = e.target.result;
70
+ img.onload = () => {
71
+ images.push({ src: e.target.result, width: img.width, height: img.height });
72
+ const wrapper = document.createElement('div');
73
+ wrapper.className = 'imageWrapper';
74
+ wrapper.appendChild(img);
75
+ imageContainer.appendChild(wrapper);
76
+ };
77
+ };
78
+ reader.readAsDataURL(file);
79
+ });
80
+ });
81
+
82
+ // Generate PDF from images
83
+ function generatePDF() {
84
+ if (images.length === 0) {
85
+ alert('Please upload at least one image.');
86
+ return;
87
+ }
88
+
89
+ const doc = new jsPDF();
90
+ const pageWidth = doc.internal.pageSize.getWidth();
91
+ const pageHeight = doc.internal.pageSize.getHeight();
92
+ const margin = 10;
93
+ const maxImgWidth = pageWidth - 2 * margin;
94
+ const maxImgHeight = pageHeight - 2 * margin;
95
+
96
+ images.forEach((image, index) => {
97
+ if (index > 0) {
98
+ doc.addPage();
99
+ }
100
+
101
+ // Calculate scaling to fit image within page
102
+ let imgWidth = image.width;
103
+ let imgHeight = image.height;
104
+ const ratio = Math.min(maxImgWidth / imgWidth, maxImgHeight / imgHeight);
105
+ imgWidth = imgWidth * ratio;
106
+ imgHeight = imgHeight * ratio;
107
+
108
+ // Center the image on the page
109
+ const x = (pageWidth - imgWidth) / 2;
110
+ const y = (pageHeight - imgHeight) / 2;
111
+
112
+ doc.addImage(image.src, 'JPEG', x, y, imgWidth, imgHeight);
113
+ });
114
+
115
+ doc.save('images.pdf');
116
+ }
117
+ </script>
118
+ </body>
119
+ </html>