forked from gaureshpai/cert-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv2.html
More file actions
583 lines (495 loc) · 19.5 KB
/
v2.html
File metadata and controls
583 lines (495 loc) · 19.5 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AAKAR 2025 Certificate Generator</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 15px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #e91e63 0%, #ad1457 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
font-weight: 300;
}
.header p {
font-size: 1.1rem;
opacity: 0.9;
}
.controls {
padding: 30px;
background: #f8f9fa;
border-bottom: 1px solid #e9ecef;
}
.control-group {
display: flex;
gap: 20px;
align-items: center;
flex-wrap: wrap;
}
.btn {
background: linear-gradient(135deg, #e91e63 0%, #ad1457 100%);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
font-weight: 500;
transition: all 0.3s ease;
text-decoration: none;
display: inline-block;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.status {
padding: 20px 30px;
background: #e3f2fd;
border-left: 4px solid #2196f3;
margin: 20px 30px;
border-radius: 0 8px 8px 0;
}
.progress {
margin: 20px 30px;
}
.progress-bar {
width: 100%;
height: 8px;
background: #e9ecef;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #e91e63 0%, #ad1457 100%);
width: 0%;
transition: width 0.3s ease;
}
.progress-text {
margin-top: 10px;
text-align: center;
color: #666;
font-weight: 500;
}
.participants-list {
max-height: 400px;
overflow-y: auto;
margin: 20px 30px;
border: 1px solid #e9ecef;
border-radius: 8px;
}
.participant-item {
padding: 15px;
border-bottom: 1px solid #f1f3f4;
display: flex;
justify-content: space-between;
align-items: center;
background: white;
}
.participant-item:hover {
background: #f8f9fa;
}
.participant-info {
flex: 1;
}
.participant-id {
font-weight: bold;
color: #2c3e50;
}
.participant-details {
color: #666;
font-size: 0.9rem;
margin-top: 5px;
}
/* Certificate with background image */
.certificate {
width: 1200px;
height: 850px;
position: relative;
margin: 20px auto;
display: none;
}
.certificate-bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.certificate-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
}
/* Updated text overlay styles with corrected positioning */
.name-overlay {
position: absolute;
top: 528px;
left: 50%;
transform: translateX(-50%);
font-size: 26px;
font-weight: bold;
color: #000;
font-family: 'Times New Roman', serif;
text-align: center;
width: 100%;
}
.college-overlay {
position: absolute;
top: 588px;
left: 50%;
transform: translateX(-50%);
font-size: 24px;
font-weight: normal;
color: #000;
font-family: 'Times New Roman', serif;
text-align: center;
width: 100%;
}
.event-overlay {
position: absolute;
top: 648px;
left: 50%;
transform: translateX(-50%);
font-size: 24px;
font-weight: bold;
color: #000;
font-family: 'Times New Roman', serif;
text-align: center;
width: 100%;
}
@media print {
body * {
visibility: hidden;
}
.certificate,
.certificate * {
visibility: visible;
}
.certificate {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
margin: 0;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>AAKAR 2025 Certificate Generator</h1>
<p>Generate participation certificates for AAKAR 2025 event participants</p>
</div>
<div class="controls">
<div class="control-group">
<input title="Select a CSV file" type="file" id="csvFileInput" accept=".csv" style="margin-right: 10px;">
<button class="btn" onclick="loadParticipants()">Load CSV Data</button>
<button class="btn" onclick="generateAllCertificates()" id="generateBtn" disabled>Generate All
Certificates</button>
<button class="btn" onclick="downloadAllCertificates()" id="downloadBtn" disabled>Download All
Certificates</button>
</div>
</div>
<div class="status" id="status" style="display: none;">
<strong>Status:</strong> <span id="statusText">Ready</span>
</div>
<div class="progress" id="progress" style="display: none;">
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="progress-text" id="progressText">0 / 0 certificates generated</div>
</div>
<div class="participants-list" id="participantsList" style="display: none;">
<!-- Participants will be loaded here -->
</div>
<!-- Certificate Template with Background Image -->
<div class="certificate" id="certificateTemplate">
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwMCIgaGVpZ2h0PSI4NTAiIHZpZXdCb3g9IjAgMCAxMjAwIDg1MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjEyMDAiIGhlaWdodD0iODUwIiBmaWxsPSJ3aGl0ZSIvPgo8dGV4dCB4PSI2MDAiIHk9IjQwMCIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZm9udC1mYW1pbHk9IkFyaWFsIiBmb250LXNpemU9IjI0IiBmaWxsPSIjY2NjIj5DZXJ0aWZpY2F0ZSBUZW1wbGF0ZSBQbGFjZWhvbGRlcjwvdGV4dD4KICA8L3N2Zz4="
class="certificate-bg" alt="Certificate Background" />
<div class="certificate-content">
<div class="name-overlay" id="certParticipantName">[Participant Name]</div>
<div class="college-overlay" id="certCollegeName">[College Name]</div>
<div class="event-overlay" id="certEventName">[Event Name]</div>
</div>
</div>
</div>
<script>
let participants = [];
let certificates = [];
function showStatus(message, type = 'info') {
const status = document.getElementById('status');
const statusText = document.getElementById('statusText');
status.style.display = 'block';
statusText.textContent = message;
if (type === 'error') {
status.style.background = '#ffebee';
status.style.borderColor = '#f44336';
} else if (type === 'success') {
status.style.background = '#e8f5e8';
status.style.borderColor = '#4caf50';
} else {
status.style.background = '#e3f2fd';
status.style.borderColor = '#2196f3';
}
}
function updateProgress(current, total) {
const progress = document.getElementById('progress');
const progressFill = document.getElementById('progressFill');
const progressText = document.getElementById('progressText');
progress.style.display = 'block';
const percentage = (current / total) * 100;
progressFill.style.width = percentage + '%';
progressText.textContent = `${current} / ${total} certificates generated`;
}
function parseCSV(csvText) {
const lines = csvText.split('\n');
const result = [];
for (let i = 1; i < lines.length; i++) {
const line = lines[i].trim();
if (!line) continue;
// Handle CSV parsing with proper quote handling
const columns = [];
let currentColumn = '';
let inQuotes = false;
for (let j = 0; j < line.length; j++) {
const char = line[j];
if (char === '"') {
inQuotes = !inQuotes;
} else if (char === ',' && !inQuotes) {
columns.push(currentColumn.trim());
currentColumn = '';
} else {
currentColumn += char;
}
}
columns.push(currentColumn.trim());
if (columns.length >= 4 && columns[0] && columns[1]) {
result.push({
id: columns[0],
name: columns[1],
college: columns[2],
events: columns[3]
});
}
}
return result;
}
async function loadParticipants() {
try {
showStatus('Loading participants data...');
let csvText = '';
const fileInput = document.getElementById('csvFileInput');
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
csvText = await file.text();
} else {
// Fallback to sample data
csvText = `ID,Name,College,Events,
28,Radhesh Ratnakar Pai,Yenepoya School Of Engineering & Technology,"Debug To Live (Debugging), The Developer's Dilemma (Web Dev)",
104,Mohammed Shahad,Yenepoya School Of Engineering & Technology,Squid Game ,
105,shaikh mohammed danish,Yenepoya School Of Engineering & Technology,Squid Game ,
347,Meer Mohammed Saif,Yenepoya School Of Engineering & Technology,Valo Squad (Valorant),
467,radhesh,Yenepoya School Of Engineering & Technology,Code Without Sight (Blind Coding),
468,Rida Fathima,Yenepoya School Of Engineering & Technology,Pattern Of Destiny (Rangoli),
28-Jan,Aromal Biju,Yenepoya School Of Engineering & Technology,"Debug To Live (Debugging), The Developer's Dilemma (Web Dev)",
28-0,Rinu Manoj,Yenepoya School Of Engineering & Technology,"Debug To Live (Debugging), The Developer's Dilemma (Web Dev)",`;
}
const rawParticipants = parseCSV(csvText);
participants = [];
rawParticipants.forEach(participant => {
// Handle multiple events separated by commas or &
const events = participant.events.split(/[,&]/).map(e => e.trim().replace(/['"]/g, ''));
if (events.length > 1) {
events.forEach((event, index) => {
participants.push({
...participant,
events: event,
isLeader: index === 0,
isGroup: index > 0,
eventIndex: index
});
});
} else {
participants.push({
...participant,
events: events[0] || participant.events,
isLeader: true,
isGroup: false,
eventIndex: 0
});
}
});
displayParticipants();
document.getElementById('generateBtn').disabled = false;
showStatus(`Loaded ${participants.length} participant entries`, 'success');
} catch (error) {
console.error('Error loading participants:', error);
showStatus('Error loading participants data', 'error');
}
}
function displayParticipants() {
const participantsList = document.getElementById('participantsList');
participantsList.style.display = 'block';
participantsList.innerHTML = participants.map(p => `
<div class="participant-item">
<div class="participant-info">
<div class="participant-id">ID: ${p.id}</div>
<div class="participant-details">
<strong>${p.name}</strong> - ${p.college}<br>
Event: ${p.events} ${p.isLeader ? '(Leader)' : ''} ${p.isGroup ? '(Group)' : ''}
</div>
</div>
</div>
`).join('');
}
async function generateAllCertificates() {
if (participants.length === 0) {
showStatus('No participants loaded', 'error');
return;
}
showStatus('Generating certificates...');
certificates = [];
for (let i = 0; i < participants.length; i++) {
const participant = participants[i];
updateProgress(i + 1, participants.length);
const certificateData = await generateCertificateWithCanvas(participant);
if (certificateData) {
certificates.push(certificateData);
}
await new Promise(resolve => setTimeout(resolve, 100));
}
document.getElementById('downloadBtn').disabled = false;
showStatus(`Generated ${certificates.length} certificates successfully!`, 'success');
}
function generateCertificateWithCanvas(participant) {
return new Promise((resolve) => {
const canvas = document.createElement('canvas');
canvas.width = 1200;
canvas.height = 850;
const ctx = canvas.getContext('2d');
// Set background color
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw a simple border and background design
ctx.strokeStyle = '#e91e63';
ctx.lineWidth = 10;
ctx.strokeRect(50, 50, 1100, 750);
// Draw header
ctx.fillStyle = '#e91e63';
ctx.font = 'bold 48px Arial';
ctx.textAlign = 'center';
ctx.fillText('AAKAR 2025', 600, 150);
ctx.font = 'bold 36px Arial';
ctx.fillText('CERTIFICATE', 600, 220);
ctx.font = 'normal 24px Arial';
ctx.fillText('OF PARTICIPATION', 600, 260);
// Certificate text
ctx.fillStyle = '#000000';
ctx.font = 'normal 20px Times New Roman';
ctx.fillText('This is to certify that Mr/Ms', 600, 350);
// Participant name - corrected positioning
ctx.font = 'bold 28px Times New Roman';
ctx.fillStyle = '#000000';
ctx.fillText(participant.name, 600, 420);
// Draw underline for name
const nameWidth = ctx.measureText(participant.name).width;
ctx.beginPath();
ctx.moveTo(600 - nameWidth / 2 - 20, 430);
ctx.lineTo(600 + nameWidth / 2 + 20, 430);
ctx.strokeStyle = '#e91e63';
ctx.lineWidth = 2;
ctx.stroke();
// College text
ctx.font = 'normal 20px Times New Roman';
ctx.fillStyle = '#000000';
ctx.fillText('of', 600, 480);
ctx.font = 'bold 22px Times New Roman';
ctx.fillText(participant.college, 600, 520);
// Event text
ctx.font = 'normal 20px Times New Roman';
ctx.fillText('has participated in', 600, 570);
ctx.font = 'bold 24px Times New Roman';
ctx.fillText(participant.events, 600, 610);
ctx.font = 'normal 18px Times New Roman';
ctx.fillText('event held as a part of AJIET\'s AAKAR 2025 held on 21st and 22nd of May 2025.', 600, 650);
// Convert to image data
const imageData = canvas.toDataURL('image/png');
// Create filename
let filename = `certificate_${participant.id}`;
if (participant.isGroup) {
filename += `_group_${participant.eventIndex}`;
} else if (participant.eventIndex > 0) {
filename += `_event_${participant.eventIndex}`;
}
filename += '.png';
resolve({
participant: participant,
imageData: imageData,
filename: filename
});
});
}
function downloadAllCertificates() {
if (certificates.length === 0) {
showStatus('No certificates to download', 'error');
return;
}
showStatus('Downloading certificates...');
certificates.forEach((cert, index) => {
if (cert && cert.imageData) {
setTimeout(() => {
const link = document.createElement('a');
link.download = cert.filename;
link.href = cert.imageData;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}, index * 500);
}
});
showStatus(`Downloading ${certificates.length} certificates...`, 'success');
}
// Initialize with sample data
window.addEventListener('load', () => {
loadParticipants();
});
</script>
</body>
</html>