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.)
Thanks tobiashm.