-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
160 lines (139 loc) · 3.86 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload CSV File</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #ffffff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
max-width: 500px;
width: 100%;
text-align: center;
transition: transform 0.3s ease-in-out;
}
.container:hover {
transform: translateY(-5px);
}
h1 {
color: #333;
font-size: 24px;
margin-bottom: 25px;
font-weight: 600;
}
label {
display: block;
margin-bottom: 15px;
font-size: 18px;
color: #555;
}
input[type="file"] {
display: block;
margin: 0 auto 20px auto;
padding: 12px 15px;
font-size: 16px;
border: 2px solid #ccc;
border-radius: 5px;
width: 100%;
max-width: 350px;
box-sizing: border-box;
transition: border-color 0.3s ease;
}
input[type="file"]:hover {
border-color: #007bff;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 12px 25px;
font-size: 18px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.3s ease;
margin-top: 15px;
}
button:hover {
background-color: #0056b3;
transform: translateY(-3px);
}
button:active {
background-color: #004494;
}
.hidden {
display: none;
}
.error-message {
color: red;
margin-top: 20px;
font-size: 14px;
}
.btn-secondary {
background-color: #6c757d;
margin-left: 10px;
}
.btn-secondary:hover {
background-color: #5a6268;
}
.btn-secondary:active {
background-color: #495057;
}
</style>
</head>
<body>
<div class="container">
<h1>Upload CSV File</h1>
<form id="uploadForm" action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">Choose CSV File:</label>
<input type="file" name="file" id="file" accept=".csv" required>
<button type="button" id="generateBtn">Generate PDF</button>
<button type="button" id="previewBtn" class="hidden">Preview PDF</button>
<button type="button" id="downloadBtn" class="hidden btn-secondary">Download PDF</button>
</form>
<div class="error-message hidden" id="errorMessage"></div>
</div>
<script>
document.getElementById('generateBtn').addEventListener('click', function() {
var formData = new FormData(document.getElementById('uploadForm'));
fetch('upload.php', {
method: 'POST',
body: formData,
})
.then(response => response.blob())
.then(blob => {
// Create a URL for the generated PDF
const pdfUrl = URL.createObjectURL(blob);
// Display the preview and download buttons
document.getElementById('previewBtn').classList.remove('hidden');
document.getElementById('downloadBtn').classList.remove('hidden');
// Set up the preview button
document.getElementById('previewBtn').addEventListener('click', function() {
window.open(pdfUrl, '_blank');
});
// Set up the download button
document.getElementById('downloadBtn').addEventListener('click', function() {
const a = document.createElement('a');
a.href = pdfUrl;
a.download = 'products.pdf';
a.click();
});
})
.catch(error => {
console.error('Error generating PDF:', error);
});
});
</script>
</body>
</html>