forked from gaureshpai/cert-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv3.html
More file actions
645 lines (548 loc) · 21.6 KB
/
v3.html
File metadata and controls
645 lines (548 loc) · 21.6 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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<!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;
}
/* Text overlay styles - Based on your template image positioning */
.name-overlay {
position: absolute;
top: 455px;
left: 380px;
font-size: 24px;
font-weight: bold;
color: #000;
font-family: 'Times New Roman', serif;
}
.college-overlay {
position: absolute;
top: 515px;
left: 70px;
font-size: 22px;
font-weight: bold;
color: #000;
font-family: 'Times New Roman', serif;
max-width: 1080px;
}
.event-overlay {
position: absolute;
top: 570px;
left: 90px;
font-size: 16px;
font-weight: normal;
color: #000;
font-family: 'Times New Roman', serif;
max-width: 800px;
}
@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">
<button class="btn" onclick="loadParticipants()">Load Participants</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="/certificate-template.png" 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 = [];
// Fixed CSV data from index.csv
const csvData = './index.csv'; //ID,Name,College,Events
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;
}
function loadParticipants() {
try {
showStatus('Loading participants data...');
const rawParticipants = parseCSV(csvData);
participants = [];
rawParticipants.forEach(participant => {
// Clean the events string
let eventsString = participant.events.replace(/"/g, '').trim();
// Handle multiple events separated by commas
if (eventsString.includes(',')) {
const events = eventsString.split(',').map(e => e.trim());
events.forEach((event, index) => {
participants.push({
id: participant.id,
name: participant.name,
college: participant.college,
events: event,
isLeader: index === 0,
isGroup: index > 0,
eventIndex: index,
filename: `${participant.id}_${index === 0 ? 'leader' : 'group'}.png`
});
});
} else {
// Single event
participants.push({
id: participant.id,
name: participant.name,
college: participant.college,
events: eventsString,
isLeader: true,
isGroup: false,
eventIndex: 0,
filename: `${participant.id}_solo.png`
});
}
});
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}<br>
Type: ${p.isLeader ? 'Leader' : p.isGroup ? 'Group Member' : 'Solo'}<br>
Filename: ${p.filename}
</div>
</div>
</div>
`).join('');
}
async function generateAllCertificates() {
if (participants.length === 0) {
showStatus('No participants loaded', 'error');
return;
}
showStatus('Generating certificates...');
certificates = [];
// Check if certificate template image exists
const testImg = new Image();
testImg.onerror = () => {
showStatus('Certificate template image not found. Using canvas generation.', 'info');
generateWithCanvas();
};
testImg.onload = () => {
generateWithTemplate();
};
testImg.src = '/certificate-template.png';
}
async function generateWithTemplate() {
for (let i = 0; i < participants.length; i++) {
const participant = participants[i];
updateProgress(i + 1, participants.length);
const certificateData = await generateCertificate(participant);
if (certificateData) {
certificates.push(certificateData);
}
await new Promise(resolve => setTimeout(resolve, 200));
}
document.getElementById('downloadBtn').disabled = false;
showStatus(`Generated ${certificates.length} certificates successfully!`, 'success');
}
async function generateWithCanvas() {
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, 200));
}
document.getElementById('downloadBtn').disabled = false;
showStatus(`Generated ${certificates.length} certificates successfully!`, 'success');
}
async function generateCertificate(participant) {
return new Promise((resolve) => {
// Update certificate template with participant data
document.getElementById('certParticipantName').textContent = participant.name;
document.getElementById('certCollegeName').textContent = participant.college;
document.getElementById('certEventName').textContent = participant.events;
// Show certificate for rendering
const certificate = document.getElementById('certificateTemplate');
certificate.style.display = 'block';
// Use html2canvas to convert to image
setTimeout(() => {
if (typeof html2canvas !== 'undefined') {
html2canvas(certificate, {
width: 1200,
height: 850,
scale: 2,
useCORS: true,
allowTaint: true
}).then(canvas => {
const imageData = canvas.toDataURL('image/png');
certificate.style.display = 'none';
resolve({
participant: participant,
imageData: imageData,
filename: participant.filename
});
}).catch(error => {
console.error('Error generating certificate:', error);
certificate.style.display = 'none';
resolve(null);
});
} else {
// Fallback to canvas method
certificate.style.display = 'none';
generateCertificateWithCanvas(participant).then(resolve);
}
}, 300);
});
}
function generateCertificateWithCanvas(participant) {
return new Promise((resolve) => {
const canvas = document.createElement('canvas');
canvas.width = 1200;
canvas.height = 850;
const ctx = canvas.getContext('2d');
// Create certificate background
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Pink gradient background
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
gradient.addColorStop(0, '#ff69b4');
gradient.addColorStop(1, '#ff1493');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// White certificate area
ctx.fillStyle = '#ffffff';
ctx.fillRect(100, 100, 1000, 650);
// Header
ctx.fillStyle = '#000000';
ctx.font = 'bold 36px Arial';
ctx.textAlign = 'center';
ctx.fillText('A J INSTITUTE OF ENGINEERING & TECHNOLOGY', 600, 200);
ctx.font = 'normal 18px Arial';
ctx.fillText('(A Unit of Laxmi Memorial Educational Trust ®)', 600, 230);
ctx.font = 'bold 48px Arial';
ctx.fillStyle = '#ff1493';
ctx.fillText('AAKAR', 600, 300);
ctx.fillText('2025', 600, 350);
ctx.fillStyle = '#000000';
ctx.font = 'bold 32px Arial';
ctx.fillText('CERTIFICATE', 600, 400);
ctx.font = 'normal 24px Arial';
ctx.fillText('OF PARTICIPATION', 600, 430);
// Certificate content
ctx.font = 'normal 20px Times New Roman';
ctx.fillText('This is to certify that Mr/Ms', 600, 480);
// Participant name - positioned as per template
ctx.font = 'bold 24px Times New Roman';
ctx.textAlign = 'left';
ctx.fillText(participant.name, 380, 530);
// College name
ctx.font = 'normal 22px Times New Roman';
ctx.fillText(participant.college, 60, 590);
// Event name
ctx.font = 'bold 24px Times New Roman';
ctx.fillText(participant.events, 260, 650);
// Additional text
ctx.font = 'normal 18px Times New Roman';
ctx.textAlign = 'center';
ctx.fillText('event held as a part of AJIET\'s AAKAR 2025 held on 21st and 22nd of May 2025.', 600, 700);
// Convert to image data
const imageData = canvas.toDataURL('image/png');
resolve({
participant: participant,
imageData: imageData,
filename: participant.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');
}
// Load html2canvas library
const script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js';
script.onload = () => {
console.log('html2canvas loaded successfully');
};
script.onerror = () => {
console.log('html2canvas failed to load, using canvas fallback');
};
document.head.appendChild(script);
// Auto-load participants on page load
window.addEventListener('load', () => {
loadParticipants();
});
</script>
</body>
</html>