-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (33 loc) · 1.15 KB
/
script.js
File metadata and controls
48 lines (33 loc) · 1.15 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
document.getElementById('form').addEventListener('submit', async (e) => {
e.preventDefault();
const { jsPDF } = window.jspdf;
const form = e.target;
// Extract form values
const name = form.name.value;
const photo = form.photo.files[0];
const rank = form.rank.value;
const id = form.id.value;
// Create PDF
const doc = new jsPDF();
doc.setFontSize(16);
// Add user details
doc.text(`ID Number: ${id}`, 150, 20, { align: 'right' });
// Add photo if provided
if (photo) {
const img = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(photo);
});
// Add photo to PDF
doc.addImage(img, 'JPEG', 10, 30, 60, 60);
// Add name beside the photo
doc.text(`Name: ${name}`, 75, 50);
}
// Add the congratulatory line and rank below the photo
doc.setFont('helvetica', 'bold');
doc.text(`Congratulations!! You have Secured ${rank}`, 10, 100);
// Save the PDF
doc.save('form.pdf');
});