Node module that converts HTML files to PDFs.
The PDF looks great because it is styled by HTML5 Boilerplate or Bootstrap. What? - Yes! HTML is pushed into the HTML5 template index.html
. Phantomjs renders the page and saves it to a PDF. You can even customize the style of the PDF by passing an optional path to your CSS and you can pre-process your html file before it is converted to a PDF by passing in a pre-processing function, for creating templates.
- Uses Nightmare - an Electron based headless browser.
- Simple API
- No more streams
npm install --save html5-to-pdf
HTMLToPDF = require 'html5-to-pdf'
htmlToPDF = new HTMLToPDF {
inputPath: './path/to/input.html',
outputPath: './path/to/output.pdf',
}
htmlToPDF.build (error) =>
throw error if error?
# Done!
Options are passed into the constructor.
Type: String
Required: true
Path to the input HTML
Type: String
or Buffer
Path to the input html as a String
, or Buffer
. If specified this will override inputPath.
Type: String
Required: true
Path to the output pdf file.
Type: Array<Object>
An array of objects containing a type of ['css', 'js'] and a filePath pointing to the asset.
Example:
[
{
"type": "css",
"filePath": "/path/to/asset.css"
}
// ...
]
Type: String
Default value: A4
'A3', 'A4', 'Legal', 'Letter' or 'Tabloid'
Type: Boolean
Default value: false
true for landscape, false for portait.
Type: Number
Default value: 0
- 0 - default
- 1 - none
- 2 - minimum
Type: Boolean
Default value: false
Whether to print CSS backgrounds.
Type: Number
Default value: 0
Delay in milli-seconds before rendering the PDF (give HTML and CSS a chance to load)
Type: String
Default value: html5bp
The template to use when rendering the html. You can choose between html5bp
(HTML5 Boilerplate) or htmlbootstrap
(Boostrap 3.1.1)
Type: String
Default value: the html5-to-pdf/templates/#{options.template}
The template to use for rendering the html. If this is set, it will use this instead of the template path.
Type: String
The url to use for rendering the html. If this is set, this will be used for serving up the html. This will override options.templatePath
and options.template
To use html5-to-pdf as a standalone program from the terminal run
npm install --global html5-to-pdf
Usage: command [options] <path/to/html-file-path>
Options:
-h, --help output usage information
-V, --version output the version number
-i --include <path>..<path> path to either a javascript asset, or a css asset
--page-size [size] 'A3', 'A4', 'Legal', 'Letter' or 'Tabloid'
--margin-type [n] Specify the type of margins to use: 0 - default, 1 - none, 2 - minimum
--landscape If set it will change orientation to landscape from portriat
--print-background Whether to print CSS backgrounds
-t --template [template] The template to used. Defaults to html5bp.
-d --render-delay [millis] Delay before rendering the PDF (give HTML and CSS a chance to load)
-o --output <path> Path of where to save the PDF