Grunt Task that uses wkhtmltopdf to convert HTML files to PDF

npm install grunt-wkhtmltopdf
6 downloads in the last week
18 downloads in the last month


A simple Grunt multitask that uses wkhtmltopdf to convert HTML files to PDF. Convertion to PDF takes care of @media print CSS rules and preserves links to remote web pages.

Getting Started

Setting up wkhtmltopdf

Download and install wkhtmltopdf from the project page.

Make sure wkhtmltopdf is accessible from your PATH (Try wkhtmltopdf -V in your Terminal). I'm on Mas OS X, so I created the following symlink to my /usr/local/bin/ folder:

ln -s /usr/local/bin/ /usr/local/bin/wkhtmltopdf

Use it with grunt

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-wkhtmltopdf

Then add this line to your project's grunt.js gruntfile:



Simply add task definition in your gruntfile. See the folllowing example:

    wkhtmltopdf: {
      dev: {
        src: 'path/to/some/html/file/*.html',
        dest: 'pdf/output/'
      prod: {
        src: 'path/to/some/html/file/*.html',
        dest: 'pdf/output/'

Run grunt wkhtmltopdf to execute all the targets or grunt wkhtmltopdf:targetname to execute a specific target. Every html file defined by the src parameter will be turned into a PDF and saved to dest folder.


In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

  • v0.1.0: First Release
  • v0.2.0: Fixed compatibility with grunt 0.4
  • v0.3.0: grunt-wkhtmltopdf is now a multi-task


Copyright (c) 2012 Olivier Audard
Licensed under the MIT license.

npm loves you