PhantomJS timeout error fixed in Node-Pdf from NPM

We tried using node-pdf from NPM – JavaScript Package Manager to generate PDF file from HTML file. node-pdf take HTML source as an input and return PDF file. A requirement to generate PDF format file for Photo files comprising multiple image format, So the purpose to convert photos into PDF format.


Once trying, we experienced an issue in generating PDF file when HTML file size is more than 3 MB.

We got to understand about default time out maximum to 30 Seconds for PhantomJS, So in a case when HTML file size is larger than 3 MB, PhantomJS generates timeout error and node-pdf return response as a corrupted PDF file.


Error when loading gists from = parseInt(this.options.timeout) || 30000

Fixing PhantomJS timeout issue I need to override default timeout parameter by passing timeout attributes in option.

Error when loading gists from var pdf = require(‘html-pdf’); var options = { format: ‘A4’, border: { top: "0.5cm", right: "0.5cm", bottom: "0.5cm", left: "0.5cm" }, timeout: 60000 } pdf.create(html, options).toFile(‘./photos.pdf’, function(err, res){ if (err) return console.log(err); console.log(res); });

So by increasing PhantomJS timeout I’ve fixed big size file issue.