Is there a way to trigger the PDF export feature in PhantomJS without specifying an output file with the .pdf extension? We’d like to use stdout to output the PDF.
Is there a way to trigger the PDF export feature in PhantomJS without specifying
Share
As pointed out by Niko you can use
renderBase64()to render the web page to an image buffer and return the result as a base64-encoded string.But for now this will only work for PNG, JPEG and GIF.
To write something from a phantomjs script to stdout just use the filesystem API.
I use something like this for images :
I don’t know if the PDF format for
renderBase64()will be in a future version of phanthomjs but as a workaround something along these lines may work for you:Where
outputis the path to the pdf file.