Skip to content

Commit

Permalink
pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
tawseefnabi committed Aug 24, 2021
1 parent 67f3acf commit 7463fe6
Show file tree
Hide file tree
Showing 7 changed files with 2,104 additions and 97 deletions.
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"singleQuote": true,
"printWidth": 80,
"useTabs": true,
"tabWidth": 4,
"semi": true
}
28 changes: 25 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#!/usr/bin/env node

(async () => {
console.log("start");
})();
const pdf = require('html-pdf');
const Handlebars = require('handlebars');
const handleError = require('cli-error-handler');

module.exports = (doc, options) => {
return new Promise((resolve, reject) => {
if (!doc || !doc.html || !doc.data) {
reject(new Error('Some, or all, options are missing.'));
}
if (doc.type === 'pdf') {

// Create PDF from html template generated by handlebars
// Output will be PDF file
let html = Handlebars.compile(doc.html)(doc.data);
let filepath = doc.path;
pdf.create(html).toFile(filepath, function (err, res) {
if (err) handleError('error in creating file', err);
console.log('file generated:', res.filename);
resolve(res);
});
} else {
reject('only pdf file type supported');
}
});
};
Loading

0 comments on commit 7463fe6

Please # to comment.