pdf-puppet
v0.2.4
Published
generate PDFs from HTML templates
Downloads
4
Readme
PDF Puppet
PDF Puppet is a tool for creating pdfs using HTML and CSS along with a variety of templating and styles engines.
Install:
npm install --global pdf-puppet
Usage:
Usage: pdf-puppet <config> <output>
Options:
-v, --version output the version number
-c, --config <file> Path to the config yaml file. (default: "puppet")
-o, --out <file> Path to the output pdf file. (default: "output.pdf")
-h, --help output usage information
Commands:
dev run a development server to render the markup before generating the pdf
Example:
pdf-puppet -c ./demo/twig/invoice.yml -o invoice.pdf
This will build the PDF using the files and data in the invoice.yml file and output it in the invoice.pdf file.
Dev Server
The dev server has 3 routes:
- The fallback route that generates the HTML markup in the browser
- Any route with
.pdf
in its name generates the pdf data - The route
/viewer
generates a page that shows the pdf and reloads on changes
Templating engines
The following are supported:
- Handlebars
- HTML (plain, no data)
- Mustache
- Pug
- Twig
Style engines
The following are supported:
- CSS
- SCSS
Config file
You can find sample config files in the demo folder. Here is a breakdown of the different parts --
title
: Title of document, it will appear in the title section during developmenttemplate
: Path to the template filestyles
: Path to the style filemarkupEngine
: Markup/Template engine to be used (pug, twig, etc.)format
: Print format (e.g. A4, A5, A6, etc.), overrides height and widthheight
: Specify height, defaults to auto-heightwidth
: Specify width, defaults to auto-widthoutputType
: Specify your target output type (html, pdf), defaults to pdfdev
: Development settings objectport
: Port for the dev serverhost
: Host for the dev serveropen
: Opens the browser automatically if set to true
data
: Data object to be passed to the template