Git Product home page Git Product logo

pdf-puppeteer's Introduction

PDF-Puppeteer

NPM Version Node Requirement License Downloads/week

A simple npm package to convert HTML to PDF for Node.js applications by using Puppeteer

Getting Started

Installation

To use PDF-Puppeteer in your Node app:

npm install --save pdf-puppeteer   
# or "yarn add pdf-puppeteer"

Requirements

Node 7.6.0 or greater.

Usage

First, include the convertHTMLToPDF from the package in your .js file:

const convertHTMLToPDF = require("pdf-puppeteer");

var callback = function (pdf) {
    // do something with the PDF like send it as the response
    res.setHeader("Content-Type", "application/pdf");
    res.send(pdf);
}

/**
*    Usage
*    @param html - This is the html to be converted to a pdf
*    @param callback - Do something with the PDF
*    @param [options] - Optional parameter to pass in Puppeteer PDF options
*    @param [puppeteerArgs] - Optional parameter to pass in Puppeter arguments
*    @param [remoteContent] - Default true. Optional parameter to specify if there is no remote content. Performance will be opitmized for no remote content.
*/
convertHTMLToPDF(html, callback, options, puppeteerArgs, remoteContent);

The convertHTMLToPDF function takes the four parameters detailed above. For more information on the available Puppeteer options for PDF's take a look at Puppeteer's Page PDF Options. More details on usage can be found by checking out the example in the repo. In addition, flags for configuring how Puppeteer should be launched can be set by populating the puppeteerArgs parameter. Take a look at Puppeteer's Launch Options for example arguments.

Example

To run the example in the repo: clone the repo, npm install on the package, npm install on the example, and run the app:

git clone https://github.com/westmonroe/pdf-puppeteer.git  
cd pdf-puppeteer
npm install
cd example
npm install
node index.js

Once the example is running, the PDF route can be tested using Postman. In the example folder, you will find a Postman collection called PDF-Puppeteer.postman_collection.json with the test routes and test html included.

pdf-puppeteer's People

Contributors

chriskacerguis avatar christophermllr avatar cr7boulos avatar dboulos-hs avatar dependabot[bot] avatar joehiggs avatar josephhiggs avatar mrfrase3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.