-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.js
49 lines (35 loc) · 1.06 KB
/
index2.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
const generatePDF = async (name) => {
const { PDFDocument, rgb } = PDFLib;
const exBytes = await fetch("./Blue_Simple_Achievement_Certificate.pdf")
.then(res => {
return res.arrayBuffer()
})
const exFont = await fetch("./Sanchez-Regular.ttf")
.then(res => {
return res.arrayBuffer();
})
const pdfDoc = await PDFDocument.load(exBytes);
console.log(pdfDoc);
pdfDoc.registerFontkit(fontkit)
const myFont = await pdfDoc.embedFont(exFont);
const pages = pdfDoc.getPages();
const firstPg = pages[0];
firstPg.drawText(name, {
x: 220,
y: 300,
size: 45,
font: myFont,
color: rgb(0,0,0)
});
const uri = await pdfDoc.saveAsBase64({dataUri: true});
saveAs(uri, "Blue_Simple_Achievement_Certificate.pdf", { autoBom: true });
// window.open(uri);
// document.querySelector("#mypdf").src = uri;
}
const inputs = document.getElementById("names");
const printer = document.getElementById("prints");
printer.addEventListener('click', () => {
const val = inputs.value;
generatePDF(val);
})
//generatePDF("Mubarak Ibrahim");