pdfy
Creates PDF documents from HTML templates using Headless Chrome.
Install
yarn
$ yarn add pdfy
npm
$ npm install --save pdfy
Usage
Basic
const pdfy = ;
Saving files
const pdfy = ;const options = path: 'example.pdf' // Just add the path in options //=> <Promise<Buffer>>
Bootstrap styles
See example
const pdfy = ;const axios = ; const bootstrapUrl = 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css';const data : bootstrap = await axios; const template = ` <html> <head> <style>{{ bootstrap }}</style> </head> <body> <div class="container"> <h1>Hello {{ user }}</h1> <button type="button" class="btn btn-primary">Primary</button> <button type="button" class="btn btn-secondary">Secondary</button> <button type="button" class="btn btn-success">Success</button> </div> </body> </html>`; ;//=> <Promise<Buffer>>
API
pdfy(template, data, [options])
Returns a <Promise<Buffer>>
with the generated PDF.
template
Type: string
HTML template string.
data
Type: object
Data that will be injected on the template.
options
Type: object
// Default options format: "A4" path: "" margin: top: '50px' bottom: '50px'
Related
License
MIT © Ruan Martinelli