All Projects → micromata → Pdf Renderer

micromata / Pdf Renderer

Licence: mit
Node.js based renderer using Handlebars und JSON data to generate PDFs from HTML-Pages using wkhtmltopdf

Programming Languages

javascript
184084 projects - #8 most used programming language

Install instructions

First of all please install the standalone CLI of wkhtmltopdf on your machine. If not already present, please install the latest version of io.js (tested with iojs v2.3.3). After that proceed with the normal npm install of this package. It'll automatically try to install babel globally as a preinstall script and trigger an npm dedupe as a postinstall.

After these steps you are ready to go.

Starting the demo server

npm start handles the on-the-fly transpilation of the example/server.js (which is written in ES6).

On-the-fly transpilation

The npm start handles the transpilation of the ES6 code transparently. If you want to skip the on-the-fly step you'll need to transpile the necessary files once and persist it via piping (e.g. babel index.js > index.transpiled.js). Keep in mind that some ES6 features may not be transpiled since they are already natively implemented in io.js (Arrow functions in particular). This step is dependent on the entries of the .babelrc file in combination with the package.jsonboth located in the project root.

Usage

Start you webbrowser and navigate to http://localhost:3000. This will make the content of /static available to the browser. Since directory listing isn't enabled be sure to provide an index.html as an entry point.

To generate a PDF send either a JSON-object as an HTTP-POST payload via AJAX to http://localhost:3000/makepdf or send an ordinary <form action="/makepdf" method="post"> to the same destination. Either way the object keys will be used to identify the placeholders in the serverside Handlebars template. After the POST the server will compile the template, render it to PDF and stream it back to the client.

TL;DR

  • Install wkhtmltopdf
  • Install io.js
  • Run npm install
  • Run demo server via npm start
  • Send an HTTP-POST to http://localhost:3000/makepdf with the payload {"placeholder": "Actual content"}
  • In return you will receive a PDF with the "Actual content"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].