Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require("fs");
- const path = require("path");
- const handlebars = require("handlebars");
- const pdf = require('html-pdf');
- // const data = {
- // title: "A new Brazilian School",
- // date: "05/12/2018",
- // name: "Rodolfo Luis Marcos",
- // age: 28,
- // birthdate: "12/07/1990",
- // course: "Computer Science",
- // obs: "Graduated in 2014 by Federal University of Lavras, work with Full-Stack development and E-commerce."
- // }
- function createPDF(data){
- const templateHtml = fs.readFileSync(path.join('./assets/views/', 'pdf.html'), 'utf8');
- const template = handlebars.compile(templateHtml);
- const html = template(data);
- const options = { format: 'Letter' };
- const pdfPath = path.join('./assets/pdf/', `${data.name}-${new Date().getMilliseconds()}.pdf`);
- return new Promise((resolve, reject) => {
- pdf.create(html, options).toFile(pdfPath, function(err, res) {
- if (err) {
- reject(err);
- };
- resolve(res);
- console.log(res);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement