# html5-to-pdf
**Repository Path**: hangleaf/html5-to-pdf
## Basic Information
- **Project Name**: html5-to-pdf
- **Description**: HTML to PDF converter based on markdown-to-pdf
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-19
- **Last Updated**: 2020-12-22
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# html5-to-pdf
> Node module that converts HTML files to PDFs.
[](https://david-dm.org/peterdemartini/html5-to-pdf)
[](https://david-dm.org/peterdemartini/html5-to-pdf#info=devDependencies)
[](https://travis-ci.org/peterdemartini/html5-to-pdf)
The PDF looks great because it is styled by HTML5 Boilerplate or Bootstrap. What? - Yes! HTML is pushed into the HTML5 template `index.html`. Electron renders the page and saves it to a PDF. You can customize the page by adding custom CSS and JS assets.
## v3.0.0 (BREAKING CHANGES)
* Uses [Puppeteer](https://github.com/GoogleChrome/puppeteer) in order to get more fine-grain PDF options.
* Use async/await and ES6 - no more coffee-script
* For migration in your current code, consider using the new `async` functionality in your existing promise chains (see example)
## Getting started
`npm install --save html5-to-pdf`
or
`npm install --global html5-to-pdf`
## Out in the Wild
### [CV](https://github.com/dwjohnston/cv/)
Uses `webpack` and `webpack-dev-server` to let you see your changes live, and has the option to publish to HTML or PDF.
## Output Example usage
```javascript
const HTML5ToPDF = require("../lib")
const path = require("path")
const run = async () => {
const html5ToPDF = new HTML5ToPDF({
inputPath: path.join(__dirname, "assets", "basic.html"),
outputPath: path.join(__dirname, "..", "tmp", "output.pdf"),
templatePath: path.join(__dirname, "templates", "basic"),
include: [
path.join(__dirname, "assets", "basic.css"),
path.join(__dirname, "assets", "custom-margin.css"),
],
})
await html5ToPDF.start()
await html5ToPDF.build()
await html5ToPDF.close()
console.log("DONE")
process.exit(0)
}
// Use the function in an existing promise chain
Promise.resolve( 'something' )
.then( result => {
return doSomething( result )
} )
.then( result => {
// Because async functions are promises under the hood we can treat the run function as a promise
return run()
} )
.catch( handleErrors )
// Usage in try/catch block
try {
run()
} catch (error) {
console.error(error)
}
```
---
## Typescript
A Typescript definition for this library can be obtained by installing [@types/html5-to-pdf](https://www.npmjs.com/package/@types/html5-to-pdf).
## Reference
### Options
Options are passed into the constructor.
#### options.inputPath
Type: `String`
Required: true
Path to the input HTML
#### options.inputBody
Type: `String` or `Buffer`
Path to the input html as a `String`, or `Buffer`. If specified this will override inputPath.
#### options.outputPath
Type: `String`
Path to the output pdf file.
#### options.include
Type: `Array