create pdf with node js code example
Example 1: How to Create PDFs in Node.js using PDF Kit
const fs = require("fs");
const PDFDocument = require("./pdfkit-tables");
const patients = require("./patients.json");
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream(`patients.pdf`));
doc
.image("logo.png", 50, 45, { width: 50 })
.fillColor("#444444")
.fontSize(20)
.text("Patient Information.", 110, 57)
.fontSize(10)
.text("725 Fowler Avenue", 200, 65, { align: "right" })
.text("Chamblee, GA 30341", 200, 80, { align: "right" })
.moveDown();
const table = {
headers: ["Name", "Address", "Phone", "Birthday", "Email Address", "Blood Type", "Height", "Weight"],
rows: []
};
for (const patient of patients) {
table.rows.push([patient.name, patient.address, patient.phone, patient.birthday, patient.emailAddress, patient.bloodType, patient.height, patient.weight])
}
doc.moveDown().table(table, 10, 125, { width: 590 });
doc.end();
Example 2: node js serve pdf file
app.use('/pdf', express.static(__dirname + '/pathToPDF'));