template2pdf
v0.4.1
Published
PDF conversion module using the template engine
Downloads
21
Readme
template2pdf
Installation
npm install template2pdf
Basic usage
Use the template engine, you can convert content to PDF.
import jade from 'template2pdf-jade';
import exporter from 'template2pdf';
exporter(jade({ /* jade options */ }))
.render('views/content.jade', { name: 'jade' })
.then((result) => {
return result.saveAs('/tmp/content.pdf');
}).then(() => {
//successful
});
Stream
Using the Stream, you can also chain the output.
import jade from 'template2pdf-jade';
import exporter from 'template2pdf';
import fs from 'fs';
exporter(jade({ /* jade options */ }))
.render('views/content.jade', { name: 'jade' })
.then((result) => {
result.pipe(fs.createWriteStream('/tmp/stream.pdf'));
});
Javascript & Stylesheet
You can incorporate your own stylesheets or javascript files.
import exporter from 'template2pdf';
import jade from 'template2pdf-jade';
import { resolve } from 'path';
exporter(jade())
.stylesheet('style.css')
.javascript('main.js')
.render(resolve(__dirname, './report.jade'), {
title: 'jade-example',
content: 'Example content'
})
.then((result) => {
return result.saveAs('./report.pdf');
}).then(() => {
//successful
});