pdfy
Creates PDF documents from HTML templates using Headless Chrome
Last updated 2 years ago by ruanmartinelli .
MIT · Original npm · Tarball · package.json
$ cnpm install pdfy 
SYNC missed versions from official npm registry.

pdfy

Build Status NPM downloads Dependencies

Creates PDF documents from HTML templates using Headless Chrome.

Install

yarn

$ yarn add pdfy

npm

$ npm install --save pdfy

Usage

Basic

const pdfy = require('pdfy');

pdfy(`<h1> Hello {{user}} </h1>`, { user: 'James' })
  .then(buff => {
     //=> <Buffer 32 40 2a ... >
  })

Saving files

const pdfy = require('pdfy');
const options = { path: 'example.pdf' } // Just add the path in options

pdfy(`<h1> Hello {{user}} </h1>`, { user: 'James' }, options)
//=> <Promise<Buffer>>

Bootstrap styles

See example

const pdfy = require('pdfy');
const axios = require('axios');

const bootstrapUrl = 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css';
const { data : bootstrap } = await axios.get(bootstrapUrl);

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>`;

pdfy(template, { user: 'James', bootstrap });
//=> <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

See puppeteer options

// Default options
{
  format: "A4",
  path: "",
  margin: { top: '50px', bottom: '50px' }
}

Related

License

MIT © Ruan Martinelli

Current Tags

  • 0.3.0                                ...           latest (2 years ago)

6 Versions

  • 0.3.0                                ...           2 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 4
Dependencies (3)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |