Skip to content

131/htmltar-to-pdf

Repository files navigation

Build Status Coverage Status Version License Code style

Motivation

htmltar-to-pdf is a wrapper around phantomjs that convert a HTML payload (in a tarball) as a PDF (or png) file.

Using a simple tar as input makes the whole API simple & stable.

API/usage

const html2pdf = require('htmltar-to-pdf');
const infile  = '/some/path/to/a/file.tar';

let output_path = await html2pdf(infile, [format = "pdf|png", [options ]]); //will capture (index.html in tar file)


//you wont make it any simplier...
console.log("Please find a fine PDF in", output_path);

Configuration parameters & defaults values

  let opts = {
    format         : 'A4',
    orientation    : 'portrait || landscape',
    dpi            : 72,
    index          : 'index.html',

    waitForDom     : true,
    waitForEvent   : 'customPageEvent',
    waitForTimeout : 5000 // timeout as ms

     //configure one will set up #page-footer #page-header
    pageBodyAnchor : null,
    footerFile     : null,
    headerFile     : null,
  };

Credits