From 4a06d927417a57e8cef5054be1fd6de7243c8a56 Mon Sep 17 00:00:00 2001 From: dhar Date: Thu, 12 Jun 2014 22:04:46 +0200 Subject: [PATCH 1/7] Fix typo in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1770a68..0eeeaed 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. - Update project config files to work with Grunt 0.4 - Update wkthmltopdf task to use Grunt 0.4 multi-task API - Improve predictability of the destination for created PDFs + ## License Copyright (c) 2012 Olivier Audard Licensed under the MIT license. From 5b29b57245b5c1f12a00d9f8600298c07632bce2 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Thu, 4 Sep 2014 11:05:03 -0400 Subject: [PATCH 2/7] Added ability to override the arguments I needed to be able to use a different set of arguments. Updated to allow for the args to be passed in the same way the src and dest are. Could improve by comparing the two arrays instead of simply overriding them. --- tasks/wkhtmltopdf.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tasks/wkhtmltopdf.js b/tasks/wkhtmltopdf.js index 6f6dc05..8fb4def 100644 --- a/tasks/wkhtmltopdf.js +++ b/tasks/wkhtmltopdf.js @@ -51,15 +51,24 @@ module.exports = function(grunt) { "Converting " + src + " -> " + dest ); - // Launch PhantomJS. + // default args + var args = [ + '--dpi', '96', // workarround to wkhtmltopdf letter-spacing bug (see http://code.google.com/p/wkhtmltopdf/issues/detail?id=72) + '--print-media-type', // Use @print media type + ]; + + // overrides the args + if (file.args) { + args = file.args; + } + + // adds the src and dest + args = args.concat([src, dest]); + + // Launch wkhtmltopdf. helper.convert({ code: 90, - args: [ - '--dpi', '96', // workarround to wkhtmltopdf letter-spacing bug (see http://code.google.com/p/wkhtmltopdf/issues/detail?id=72) - '--print-media-type', // Use @print media type - src, - dest - ], + args: args, done: function(err) { if (err) { grunt.log('>>>', err); From b21de20c739b44ade9d446d060a4f2f28db54a86 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 8 Dec 2014 14:54:53 -0500 Subject: [PATCH 3/7] Update README.md Updated links for wkhtmltopdf as the project has moved --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0eeeaed..3cca3a4 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ Then add this line to your project's `grunt.js` gruntfile: grunt.loadNpmTasks('grunt-wkhtmltopdf'); ``` -[wkhtmltopdf]: http://code.google.com/p/wkhtmltopdf/ -[wkhtmltopdf_dl]: http://code.google.com/p/wkhtmltopdf/downloads/list +[wkhtmltopdf]: http://wkhtmltopdf.org/ +[wkhtmltopdf_dl]: http://wkhtmltopdf.org/downloads.html [grunt]: https://github.com/gruntjs/grunt [getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md From 38007b19ad8812c5bfdb80f775e1da6e35a82c17 Mon Sep 17 00:00:00 2001 From: Andy Dayton Date: Sat, 24 Jan 2015 21:43:26 -0500 Subject: [PATCH 4/7] Try adding grunt async and creating a simple index check --- tasks/wkhtmltopdf.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tasks/wkhtmltopdf.js b/tasks/wkhtmltopdf.js index 6f6dc05..9b37a80 100644 --- a/tasks/wkhtmltopdf.js +++ b/tasks/wkhtmltopdf.js @@ -18,7 +18,9 @@ module.exports = function(grunt) { grunt.registerMultiTask('wkhtmltopdf', 'Your task description goes here.', function() { - this.files.forEach(function(file) { + var done = this.async(); + + this.files.forEach(function(file, filesIndex) { var pathlib = require('path'); // calculate the destination directory and ensure it exists, since @@ -30,7 +32,7 @@ module.exports = function(grunt) { } grunt.file.mkdir(destPath); - file.src.forEach(function(src) { + file.src.forEach(function(src, srcIndex) { var dest = file.dest; // wkhtmltopdf seems to require that the destination be a file @@ -64,6 +66,10 @@ module.exports = function(grunt) { if (err) { grunt.log('>>>', err); } + // if this is the last src of the last file, we are done. + if((filesIndex+1 >= files.length) && (srcIndex+1 >= src.length)) { + done(); + } } }); }); From 696955b345693879fa0b3baa6c8f144586cbc3d6 Mon Sep 17 00:00:00 2001 From: Andy Dayton Date: Sat, 24 Jan 2015 21:57:51 -0500 Subject: [PATCH 5/7] Added some comments --- tasks/wkhtmltopdf.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tasks/wkhtmltopdf.js b/tasks/wkhtmltopdf.js index 9b37a80..5000ec3 100644 --- a/tasks/wkhtmltopdf.js +++ b/tasks/wkhtmltopdf.js @@ -18,9 +18,13 @@ module.exports = function(grunt) { grunt.registerMultiTask('wkhtmltopdf', 'Your task description goes here.', function() { - var done = this.async(); + // using grunt async support so we can be sure task doesn't + // end before PDF processing does: http://gruntjs.com/api/inside-tasks + var done = this.async(), + files = this.files; - this.files.forEach(function(file, filesIndex) { + // iterate through each file grouping + files.forEach(function(file, filesIndex) { var pathlib = require('path'); // calculate the destination directory and ensure it exists, since @@ -67,7 +71,7 @@ module.exports = function(grunt) { grunt.log('>>>', err); } // if this is the last src of the last file, we are done. - if((filesIndex+1 >= files.length) && (srcIndex+1 >= src.length)) { + if((filesIndex+1 >= files.length) && (srcIndex+1 >= file.src.length)) { done(); } } From 69a270f60425a7077bdb33af13b4b037d33de4d4 Mon Sep 17 00:00:00 2001 From: Olivier Audard Date: Sun, 22 Feb 2015 11:03:01 +0100 Subject: [PATCH 6/7] Updated README --- README.md | 63 +++++++++++++++++++++++++++++++++++--------- tasks/wkhtmltopdf.js | 2 +- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3cca3a4..d60efb5 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ Convertion to PDF takes care of `@media print` CSS rules and preserves links to ## Getting Started -### Setting up wkhtmltopdf +### Setting up wkhtmltopdf Download and install wkhtmltopdf from the [project page][wkhtmltopdf_dl]. -Make sure `wkhtmltopdf` is accessible from your `PATH` (Try `wkhtmltopdf -V` in your Terminal). +Make sure `wkhtmltopdf` is accessible from your `PATH` (Try `wkhtmltopdf -V` in your Terminal). I'm on Mac OS X, so I created the following symlink to my `/usr/local/bin/` folder: ``` @@ -29,11 +29,6 @@ Then add this line to your project's `grunt.js` gruntfile: grunt.loadNpmTasks('grunt-wkhtmltopdf'); ``` -[wkhtmltopdf]: http://wkhtmltopdf.org/ -[wkhtmltopdf_dl]: http://wkhtmltopdf.org/downloads.html -[grunt]: https://github.com/gruntjs/grunt -[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md - ## Documentation Simply add task definition in your gruntfile. See the folllowing example: @@ -54,19 +49,61 @@ Simply add task definition in your gruntfile. See the folllowing example: 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. +### Sending arguments to `wkhtml2pdf` + +Arguments sent via the `args` key in the task definition will be forwarded to `wkhtml2pdf` as follow : + +```javascript + //... + wkhtmltopdf: { + prod: { + src: 'path/to/some/html/file/*.html', + dest: 'pdf/output/', + args: [ + '--dpi', '96', + '--print-media-type', + '--grayscale' + ] + } + }, + //... +``` + +Defining custom arguments will override default ones: + +```javascript +// grunt-wkhtml2pdf default arguments +var args = [ + '--dpi', '96', + '--print-media-type' +] +``` + +See [wkhtml2pdf documentation][wkhtmltopdf_doc] for available options + ## Contributing 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][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 - - *v0.4.0*: + - *v0.5.0*: + - Merged #12 (Fix #11) : Added async support + - Merged #9 : Added ability to override the arguments + - *v0.4.0*: - Update project config files to work with Grunt 0.4 - Update wkthmltopdf task to use Grunt 0.4 multi-task API - - Improve predictability of the destination for created PDFs + - Improve predictability of the destination for created PDFs + - *v0.3.0*: grunt-wkhtmltopdf is now a multi-task + - *v0.2.0*: Fixed compatibility with grunt 0.4 + - *v0.1.0*: First Release ## License -Copyright (c) 2012 Olivier Audard +Copyright (c) 2012 Olivier Audard Licensed under the MIT license. + + +[wkhtmltopdf]: http://wkhtmltopdf.org/ +[wkhtmltopdf_dl]: http://wkhtmltopdf.org/downloads.html +[wkhtmltopdf_doc]: http://wkhtmltopdf.org/docs.html +[grunt]: https://github.com/gruntjs/grunt +[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md diff --git a/tasks/wkhtmltopdf.js b/tasks/wkhtmltopdf.js index faf1580..375915d 100644 --- a/tasks/wkhtmltopdf.js +++ b/tasks/wkhtmltopdf.js @@ -60,7 +60,7 @@ module.exports = function(grunt) { // default args var args = [ '--dpi', '96', // workarround to wkhtmltopdf letter-spacing bug (see http://code.google.com/p/wkhtmltopdf/issues/detail?id=72) - '--print-media-type', // Use @print media type + '--print-media-type' // Use @print media type ]; // overrides the args From f7a76fa9525e77d9ca0437449e26a55bb6afc559 Mon Sep 17 00:00:00 2001 From: dhar Date: Sun, 22 Feb 2015 11:44:31 +0100 Subject: [PATCH 7/7] Fix links in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d60efb5..b55cf47 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. ## Release History - *v0.5.0*: - - Merged #12 (Fix #11) : Added async support - - Merged #9 : Added ability to override the arguments + - Merged [#12](https://github.com/dharFr/grunt-wkhtmltopdf/pull/12) (Fix [#11](https://github.com/dharFr/grunt-wkhtmltopdf/issues/11)) : Added async support + - Merged [#9](https://github.com/dharFr/grunt-wkhtmltopdf/pull/9) : Added ability to override the arguments - *v0.4.0*: - Update project config files to work with Grunt 0.4 - Update wkthmltopdf task to use Grunt 0.4 multi-task API