0.0.2 • Published 7 years ago

phantomjs-pdf-server v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

PhantomJS PDF Server

phantom-js-server is a simple Node.js (Express) server that communicates with PhantomJS 2, installed using phantomjs2 npm with phantomjs-node for communications.

It inputs a static text/html and outputs a rendered application/pdf.

Getting Started

git clone https://github.com/lahdekorpi/phantomjs-pdf-server.git
cd phantomjs-pdf-server
npm install
npm start

Testing can be done via CURL, inputs test.html and outputs test.pdf:

curl -H "Content-Type: text/html" -d "@test.html" -X POST localhost:3000/pdf > test.pdf

Please note that the HTML is expected as UTF-8 encoded text without any wrappers, form data etc.

Output is either the file with HTTP status code 200. In case of an error the server will respond with a HTTP status code 500 and a JSON object containing an error message {"error": "Empty request"}.

Because of limitations in PhantomJS the generated PDF file is temporarily stored as a file. In high load environments a ramdisk should be used.

Requirements

  • Node.js 7 (with --harmony-async-await)

WARNING

Do NOT expose directly to the interwebs. This is intended to be used in internal networks and with safe to render contents. External page loads are disabled via PhantomJS's navigationLocked but this alone doesn't guarantee anything.

License

MIT