AuburnBigEvent / BigEvent

Auburn University SGA Big Event application designed for COMP 4710 senior design project.
MIT License
0 stars 2 forks source link

Adding PDF generation module and mocha test #15

Closed CoryG89 closed 10 years ago

CoryG89 commented 10 years ago

This adds a PDF generation module that I developed yesterday. It's based on PhantomJS which is a headless browser based on Webkit (base for Safari/Chromium as well).

PhantomJS is something that has to run separately on a system from our Node server, this is also the case for all other feasible PDF generation solutions that I was able to find except one. The benefit with PhantomJS however, is that it can be installed by NPM as the phantomjs module as a local application dependency so we can list it in our package.json file and have NPM manage it with all our other dependencies. I use the node-phantom module which starts the local PhantomJS installation as a child process and uses it throughout the life of the server to generate PDFs.

The node-phantom module exposes a completely asynchronous message based interface to the local PhantomJS install in ./node_modules/phantomjs running as a child process. Using PhantomJS I can then create pages from HTML after rendering them as templates with EJS, then use PhantomJS to render that page as PDF file. Instead of creating a new page in PhantomJS, to not waste memory we reuse the same page, injecting new content each time and re-rendering a new PDF.