-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateCerti.html
104 lines (104 loc) · 4.57 KB
/
generateCerti.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
<!DOCTYPE html>
<html>
<head>
<!-- <style> -->
<!-- @import url("https://fonts.googleapis.com/css?family=Roboto&display=swap"); -->
<!-- </style> -->
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.2/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>
<script type="text/javascript" src="./base64.js"></script>
<script type="text/javascript" src="./details.js"></script>
<script type="text/javascript">
function convertToBase64() {
//Read File
var selectedFile = document.getElementById("inputFile").files;
//Check File is not Empty
if (selectedFile.length > 0) {
// Select the very first file from list
var fileToLoad = selectedFile[0];
// FileReader function for read the file.
var fileReader = new FileReader();
var base64;
// Onload of file read the file content
fileReader.onload = function(fileLoadedEvent) {
base64 = fileLoadedEvent.target.result;
// Print data in console
console.log(base64);
};
// Convert data to base64
fileReader.readAsDataURL(fileToLoad);
}
}
</script>
</head>
<body>
<script>
function generateRandomString() {
return (
Math.random()
.toString(36)
.substring(2, 15) +
Math.random()
.toString(36)
.substring(2, 15)
);
}
function downloadJpg() {
var zip = new JSZip();
coordiDetails.map((coordi, index) => {
let doc = new jsPDF("landscape", "mm", "a4");
// doc.addFont("Roboto", "normal");
// doc.setFont("Roboto");
doc.addImage(appreciation, "JPEG", 0, 0, 306, 215);
console.log('added base64 image')
if (coordi.name.length > 40) {
doc.setFontSize(14);
} else if (coordi.name.length > 30) {
doc.setFontSize(16);
} else if (coordi.name.length > 20) {
doc.setFontSize(18);
} else if (coordi.name.length > 10) {
doc.setFontSize(19);
} else {
doc.setFontSize(20);
}
doc.text(96, 110, coordi.name);
if (coordi.post.length > 40) {
doc.setFontSize(14);
} else if (coordi.post.length > 30) {
doc.setFontSize(16);
} else if (coordi.post.length > 20) {
doc.setFontSize(18);
} else if (coordi.post.length > 10) {
} else {
doc.setFontSize(20);
}
doc.text(32, 122, coordi.post);
doc.setFontSize(12);
var certiName = "t" + generateRandomString();
doc.text( 10, 208, "*The certificate can be validated by visiting https://thomso.in/certificates/" + certiName);
// var certi = doc.output("datauri");
// certi = certi.split(",")[1];
// let data = {
// certi: certi
// };
if (typeof doc !== "undefined") {
try {
zip.file(certiName + ".pdf", doc.output("blob"));
} catch {
console.error("Something went wrong!");
}
}
console.log('added certi'+index);
// doc.save(`${coordi.Name}.pdf`);
});
zip.generateAsync({ type: "blob" }).then(function(content) {
saveAs(content, "coordinates.zip");
});
}
</script>
<input id="inputFile" type="file" onchange="convertToBase64();" />
<button onclick="downloadJpg();">Download</button>
</body>
</html>