-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf-exporter.js
29 lines (23 loc) · 899 Bytes
/
pdf-exporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const html_to_pdf = require('html-pdf');
const pdfOptions = require('./config.json')['pdfOptions'];
const exportPath = require('./config.json')['exportPath'] || __dirname;
const eta = require('eta');
const path = require ('path');
const fs = require('fs');
async function createFiles(title, author, contents) {
let it = {
title : title,
author : author,
data : contents
};
let x = await eta.renderFile(path.join(__dirname, "layout.eta"), it);
const fileName = title.replaceAll(' ', '-');
const pdfFilePath = path.join(exportPath, fileName+'.pdf');
const htmlFilePath = path.join(exportPath, fileName+'.html');
html_to_pdf.create(x, pdfOptions).toFile(pdfFilePath, function(err, res) {
if (err) return console.log(err);
console.log(`Exported to file : ${res.filename}`);
});
fs.writeFileSync(htmlFilePath,x);
}
module.exports.createFiles = createFiles;