nodepdf-series
Render a list of pages to PDF:
var PDF = ; ;
Render to a specified path and/or file names:
var PDF = ; ;
Works with local files too. This renders all HTML-files in subdirectories of current path:
var glob = ;var path = ;var PDF = ; ;
Installation
npm install nodepdf-series
API
Signature:
;;
pages
is an array of urls.
options
is an object with properties:
outPath
- Which directory to store PDFs. If not set, the current directory and the URL path will be used.fileNames
- An array of filenames to use. If not set, last part of URL will be used.args
- Arguments for the PhantomJS process.- Properties the PhantomJS page accept, like
viewportSize
.
callback
is called when the rendering is done.
Default options
var defaults = viewportSize: // this should be equal to paper size width: 1050 height: 1485 paperSize: /** * A4 ratio in millimeters: 210 x 297 * DPI is hardcoded 72 in phantomJS. * A resolution of 1050px will give 1050 / 72 * 25.4 ~ 370 mm width, * which is way much larger than A4. Most printers will handle this, * and scale correctly to given paper source. */ width: 1050 height: 1485 orientation: 'portrait' margin: '1cm' args: '' captureDelay: 100;
Performance
nodepdf-series spawns only one child of phantomjs, giving some extra performance compared to nodepdf. Here is a test on 95 local html files:
$ time node nodepdf.jsreal 9m32.928suser 5m56.769ssys 0m56.142s $ time node nodepdf-series.jsreal 2m47.053suser 1m55.567ssys 0m5.104s
You may also want to spread load on all CPU-cores:
var cpus = length;var chunk = ;var each = ; var files = 'path/to/file1.html' 'path/to/file5.html' 'path/to/file9.html' 'path/to/file2.html' 'path/to/file6.html' 'path/to/file10.html' 'path/to/file3.html' 'path/to/file7.html' 'path/to/file11.html' 'path/to/file4.html' 'path/to/file8.html' 'path/to/file12.html'; var chunkSize = Math;var chunks = ; ;