mrafiqk / html-pdf-node

187 stars 119 forks source link

html-pdf-node

Pagination plugin for converts html or url to pdf

Note: This plugin will convert html page or public URL into PDF. This will work with Node.js

Installation

npm install html-pdf-node

Usage

To convert HTML page to PDF using generatePdf method:

var html_to_pdf = require('html-pdf-node');

let options = { format: 'A4' };
// Example of options with args //
// let options = { format: 'A4', args: ['--no-sandbox', '--disable-setuid-sandbox'] };

let file = { content: "<h1>Welcome to html-pdf-node</h1>" };
// or //
let file = { url: "https://example.com" };
html_to_pdf.generatePdf(file, options).then(pdfBuffer => {
  console.log("PDF Buffer:-", pdfBuffer);
});

html_to_pdf.generatePdf ( [file], [options], [callback] )

Parameters

file <Object> File object should have one of the following properties:

options <Object> Options object should have the following properties:

Return value

Promise which resolves with PDF buffer.

html_to_pdf.generatePdfs ( [files], [options], [callback] )

Parameters

files <Array<Object>> File object should have one of the follwing properties:

options <Object> Options object should have the following properties:

Return value

Promise which resolves with array of object which contains file objects with PDF buffers.

Example:

let options = { format: 'A4' };
let file = [{ url: "https://example.com", name: 'example.pdf' }];

html_to_pdf.generatePdfs(file, options).then(output => {
  console.log("PDF Buffer:-", output); // PDF Buffer:- [{url: "https://example.com", name: "example.pdf", buffer: <PDF buffer>}]
});