Created
January 21, 2019 00:08
-
-
Save afucher/361cc73ccbf8db72deea9db70e6642d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const PDFDocument = require('pdfkit'); | |
const fs = require('fs'); | |
const printHeader = doc => { | |
const opt = {continued: true}; | |
doc.text("Name", opt); | |
doc.x = 200; | |
doc.text("Start date", opt); | |
doc.x = 250; | |
doc.text("End date", opt); | |
doc.x = 300; | |
doc.text("Attendance"); | |
} | |
const printRow = (doc, course) => { | |
const opt = {continued: true}; | |
doc.text(`${course.name}`, opt); | |
doc.x = 200; | |
doc.text(`${course.start_date}`, opt); | |
doc.x = 250; | |
doc.text(`${course.end_date}`, opt); | |
doc.x = 300; | |
doc.text(`${course.attendance}`); | |
} | |
const courses = [ | |
{ | |
name: "Name1", | |
start_date: "01/02/1990", | |
end_date: "01/03/1990", | |
attendance: "30%" | |
} | |
]; | |
const doc = new PDFDocument; | |
// Pipe its output somewhere, like to a file or HTTP response | |
// See below for browser usage | |
doc.pipe(fs.createWriteStream('output.pdf')); | |
printHeader(doc); | |
courses.forEach(course => { | |
printRow(doc, course); | |
}) | |
doc.end(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment