-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
187 lines (165 loc) · 5.4 KB
/
index.html
File metadata and controls
187 lines (165 loc) · 5.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Convert Uploaded HTML to PDF</title>
<script src="https://mrtusarrx.github.io/html2pdf-html/index.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
text-align: center;
color: #000;
}
.navbar {
width: 100%;
background-color: #333;
overflow: hidden;
position: fixed;
top: 0;
left: 0;
z-index: 100;
}
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
font-size: 17px;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.content {
padding-top: 60px; /* Add top padding to prevent navbar overlap */
}
h1 {
color: #333;
font-size: 2em;
margin-bottom: 20px;
}
input[type="file"] {
padding: 10px;
font-size: 1em;
margin: 20px 0;
background-color: #fff;
border: 2px solid #ccc;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
input[type="file"]:hover {
border-color: #666;
}
button {
background-color: #4CAF50;
color: white;
padding: 12px 24px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
}
button:hover {
background-color: #45a049;
transform: scale(1.05);
}
#content {
margin-top: 30px;
max-width: 600px;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: none;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#uploadMessage {
margin-top: 20px;
font-size: 1.2em;
color: green;
display: none;
}
</style>
</head>
<body>
<div class="navbar">
<a href="text2pdf.html">Text To Html</a>
</div>
<div class="content">
<h1>Upload your HTML file</h1>
<input type="file" id="htmlFile" accept=".html">
<div class="spinner" id="spinner" style="display: none;"></div>
<div id="uploadMessage">File uploaded successfully! Click "Convert" to generate PDF.</div>
<button id="convert" disabled>Convert to PDF</button>
<div id="content"></div>
</div>
<script>
let fileName = '';
document.getElementById('htmlFile').addEventListener('change', function () {
var fileInput = document.getElementById('htmlFile');
var spinner = document.getElementById('spinner');
var uploadMessage = document.getElementById('uploadMessage');
var convertButton = document.getElementById('convert');
var contentDiv = document.getElementById('content');
if (fileInput.files.length === 0) {
alert("Please select an HTML file first.");
return;
}
spinner.style.display = 'block';
uploadMessage.style.display = 'none';
convertButton.disabled = true;
contentDiv.style.display = 'none';
var file = fileInput.files[0];
fileName = file.name.replace('.html', '');
var reader = new FileReader();
reader.onload = function(event) {
spinner.style.display = 'none';
uploadMessage.style.display = 'block';
convertButton.disabled = false;
var htmlContent = event.target.result;
contentDiv.innerHTML = htmlContent;
};
reader.readAsText(file);
});
document.getElementById('convert').addEventListener('click', function () {
var contentDiv = document.getElementById('content');
contentDiv.style.display = 'block';
var opt = {
margin: 0.5,
filename: fileName + '.pdf',
image: { type: 'jpeg', quality: 1 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
};
setTimeout(() => {
html2pdf().from(contentDiv).set(opt).save();
}, 500);
});
</script>
</body>
</html>