PhantomJs - How to make a multi-page PDF file

I can create single page PDF files using phantomJS; but I can’t find in the document how to create different pages (each page coming from an html view) and put them in one PDF file? I am using node module - phantom for NodeJS

+6
source share
1 answer

Just need to specify paperSize .

Similar to this with the "phantom" module : "0.5.1"

 function(next) { phantom.create(function(doc) { next(null, doc); }, "phantomjs", Math.floor(Math.random()*(65535-49152+1)+49152)); }, function(ph, next) { ph.createPage(function(doc) { next(null, doc); }); }, function(page, next) { page.set('paperSize', {format: 'A4', orientation: 'portrait'}); page.set('zoomFactor', 1); } 

Then just use page-break-before: always; in your HTML content every time you want to open a new page.

PS: In this example, I am using async.waterfall

PPS: Math.random on the port number is used to avoid module failure if simultaneous phantom binary calls are called. It works well - if someone wants to post something better, even if a little off topic, feel free to do it

+11
source

Source: https://habr.com/ru/post/946969/


All Articles