pdf-report
v0.1.2
Published
A node module that is capable of generating pdf reports from HTML templates.
Downloads
28
Readme
pdf-report
A node module that is capable of generating pdf reports from HTML templates.
Introduction
pdf-report
was created out of the need to reliably generate PDF reports based off of templated information. There were many other tools out there that did similar jobs to this but had a poor code base; this tool aims to achieve a better code base and more support.
Getting started
To install pdf-report
, simply run the following command in your terminal (from your project directory):
npm install pdf-report --save
Example Code
// external dependencies
const PDFReport = require('pdf-report');
const path = require('path');
const fs = require('fs');
// constants/variables
const html = fs.readFileSync(path.join(__dirname, 'template.html')).toString();
const fileName = path.join(__dirname, 'example.pdf');
// logic
report.toFile(fileName)
.then(function(filePath) {
console.log('open', filePath);
})
.catch(function(error) {
console.log('error', error);
});
API
Possible Options (when instantiating)
{
height: '10.5in',
width: '8in',
orientation: 'portrait',
quality: 75,
timeout: 30000,
assetsDirectory: null,
header: {
height: '26mm'
},
footer: {
height: '18mm'
}
}
Consuming the Generated Report
After the report has been generated, it can be accessed via one of the following methods:
.toFile(pathToSave)
- generates the report and saves it to disk at the specified path.toBuffer()
- generates the report and returns the buffer.toStream()
- generates the report and returns a read stream to the file
Styles, Header & Footer
- If you'd like to style the report, you must include a single
<style>
tag in your HTML. - If you'd like to put a header on every page, be sure to place a single
<header>
tag in your HTML. - If you'd like to put a footer on every page, be sure to place a single
<footer>
tag in your HTML.