Skip to content

Instantly share code, notes, and snippets.

@raynoppe
Created May 25, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raynoppe/616e5052a6f924fcd8abaa3d88980c73 to your computer and use it in GitHub Desktop.
Save raynoppe/616e5052a6f924fcd8abaa3d88980c73 to your computer and use it in GitHub Desktop.
node pdf creator
const fs = require('fs');
var pdf = require("pdf-creator-node");
var moment = require('moment');
var appRoot = require('app-root-path');
// read html file
var html = fs.readFileSync('./includes/orderpdf.html', 'utf8');
var options = {
format: "A4",
orientation: "landscape",
border: "6mm",
};
if (req.body.pdffile && req.body.pdffile != '') {
try {
const unlfile = `${appRoot}/uploads/${req.body.pdffile}`;
fs.unlinkSync(unlfile);
} catch (error) {
console.log(error);
}
}
const newts = new Date().getTime();
const newfile = `${newts}.pdf`;
// app.use("/uploads", express.static(__dirname + '/uploads'));
var document = {
html: html,
data: displaydata,
path: `${appRoot}/uploads/${newfile}`
};
const pdfout = await pdf.create(document, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment