-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
138 lines (113 loc) · 3.58 KB
/
index.js
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
//import { saveAs } from "./FileSaver";
const generatePDF = async (name, Mname, religion,
nationality, placeOfBirth, dobInFig, dobInWords,
lCollege, dateOfAd, conduct, dateOfLeav,
yearInStud, reason, remarks) => {
const {PDFDocument, rgb} = PDFLib;
const existingPdfBytes = await fetch("./LC.pdf").then((res) =>
res.arrayBuffer()
);
const pdfDoc = await PDFDocument.load(existingPdfBytes)
const pages =pdfDoc.getPages();
const firstPg = pages[0];
firstPg.drawText(name, {
x:290,
y:588,
size: 12
});
firstPg.drawText(Mname, {
x: 290,
y: 558,
size: 12,
});
firstPg.drawText(religion, {
x: 290,
y: 529,
size: 12,
});
firstPg.drawText(nationality, {
x: 290,
y: 499,
size: 12,
});
firstPg.drawText(placeOfBirth, {
x: 290,
y: 469,
size: 12,
});
firstPg.drawText(dobInFig, {
x: 290,
y: 440,
size: 12,
});
firstPg.drawText(dobInWords, {
x: 290,
y: 411,
size: 12,
});
firstPg.drawText(lCollege, {
x: 290,
y: 381,
size: 12,
});
firstPg.drawText(dateOfAd, {
x: 290,
y: 352,
size: 12,
});
firstPg.drawText(conduct, {
x: 290,
y: 323,
size: 12,
});
firstPg.drawText(dateOfLeav, {
x: 290,
y: 293,
size: 12,
});
firstPg.drawText(yearInStud, {
x: 290,
y: 264,
size: 12,
});
firstPg.drawText(reason, {
x: 290,
y: 235,
size: 12,
});
firstPg.drawText(remarks, {
x: 290,
y: 205,
size: 12,
});
const uri = await pdfDoc.saveAsBase64({dataUri: true});
// Create a new HTML page with an embedded PDF
const newWindow = window.open();
newWindow.document.write(
`<html><head><title>Generated PDF</title></head><body><embed src="${uri}" type="application/pdf" width="100%" height="100%" /></body></html>`
);
newWindow.document.close();
//saveAs(uri, "LC.pdf", {autoBom: true})
document.querySelector("#mypdf").src = uri;
};
const submitBtn = document.getElementById("submit")
submitBtn.addEventListener("click", ()=> {
const userName = document.querySelector("#name").value
const userMname = document.querySelector("#Mname").value
const userreligion = document.querySelector("#religion").value
const usernationality = document.querySelector("#nationality").value
const userplaceOfBirth = document.querySelector("#placeOfBirth").value
const userdobInFig = document.querySelector("#dobInFig").value
const userdobInWords = document.querySelector("#dobInWords").value
const userlCollege = document.querySelector("#lCollege").value
const userdateOfAd = document.querySelector("#dateOfAd").value
const userconduct = document.querySelector("#conduct").value
const userdateOfLeav = document.querySelector("#dateOfLeav").value
const useryearInStud = document.querySelector("#yearInStud").value
const userreason = document.querySelector("#reason").value
const userremarks = document.querySelector("#remarks").value
generatePDF(userName, userMname, userreligion, usernationality,
userplaceOfBirth, userdobInFig, userdobInWords,
userlCollege, userdateOfAd,userconduct, userdateOfLeav,
useryearInStud, userreason, userremarks)
})