If you're deploying your app to somewhere where you can't be sure to have reliable disk read/write access, the normal strategy of writing to a temp-file doesn't work.
Instead we can open a pipe to the Phantom.js process, and then pass in the HTML via stdin
, and then have the rasterize.js
script write out the resulting PDF to stdout
, which we can then capture.
Any log messages from the Phantom.js process can be passed via stderr
if we want.
If we're using the default Rails setup for session handling, i.e. a _session_id
cookie, we can just pass in the session ID and have the rasterize.js
script fake a session cookie.
We can provide some additional configuration for the Phantom.js process using a config.json
file.
(I can't remember exactly why we set the things as we did, but some of them were needed.)
Thank you very much for the detail. I am more looking for a library which doesn't like WKHTMLTOPDF where you need to install it in the server. I am looking for an open source MIT license based tool to convert the html to pdf where the html more like a letterhead with images and all.
There is an another JS library called openthmltopdf but couldn't find any rails conversion of it. I am a newbie and so I could not convert the java code like you to ruby.
Does the above code can work with the image url referenced in the html?
Apologies for my neutral english written and please ignore my grammar mistakes