how to make a pdf certificate generator

Solutions on MaxInterview for how to make a pdf certificate generator by the best coders in the world

showing results for - "how to make a pdf certificate generator"
Mario
20 Jan 2017
1/*
2    This code comes from Vincent Lab
3    And it has a video version linked here: https://www.youtube.com/watch?v=zEcimv9fzqU
4*/
5
6// Import dependencies
7const fs = require("fs");
8const moment = require("moment");
9const PDFDocument = require("pdfkit");
10
11// Create the PDF document
12const doc = new PDFDocument({
13    layout: "landscape",
14    size: "A4",
15});
16
17// The name
18const name = "Sophia Sweet"
19
20// Pipe the PDF into an name.pdf file
21doc.pipe(fs.createWriteStream(`${name}.pdf`));
22
23// Draw the certificate image
24doc.image("images/certificate.png", 0, 0, { width: 842 });
25
26// Remember to download the font
27// Set the font to Dancing Script
28doc.font("fonts/DancingScript-VariableFont_wght.ttf");
29
30// Draw the name
31doc.fontSize(60).text(name, 20, 265, {
32    align: "center"
33});
34
35// Draw the date
36doc.fontSize(17).text(moment().format("MMMM Do YYYY"), -275, 430, {
37    align: "center"
38});
39
40// Finalize the PDF and end the stream
41doc.end();