From 37720677f0d342c4ab364805c6280e1d18316c71 Mon Sep 17 00:00:00 2001 From: Jonathan Guillotte-Blouin Date: Mon, 27 Jun 2016 22:04:57 -0400 Subject: [PATCH 1/5] little fix in the "Use" base case --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 989c078..5292b70 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ Assuming you've got a JSON-formatted resume handy, generating resumes in different formats and combinations is easy. Just run: ```bash -hackmyresume BUILD [-t theme]. +hackmyresume BUILD TO [-t theme]. ``` Where `` is one or more .json resume files, separated by spaces; From be8a7a8361645aa66ff89d87c885073f3676cc1a Mon Sep 17 00:00:00 2001 From: ael-code Date: Fri, 21 Oct 2016 20:00:30 +0200 Subject: [PATCH 2/5] instruct wkhtmltopdf to insert top/bottom margins added `--margin-top 10` and `-margin-bottom 10` options in the invocation of `wkhtmltopdf`. --- src/generators/html-pdf-cli-generator.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/html-pdf-cli-generator.coffee b/src/generators/html-pdf-cli-generator.coffee index 29884af..53e25b9 100644 --- a/src/generators/html-pdf-cli-generator.coffee +++ b/src/generators/html-pdf-cli-generator.coffee @@ -68,7 +68,7 @@ engines = # Save the markup to a temporary file tempFile = fOut.replace /\.pdf$/i, '.pdf.html' FS.writeFileSync tempFile, markup, 'utf8' - SPAWN 'wkhtmltopdf', [ tempFile, fOut ], false, on_error, @ + SPAWN 'wkhtmltopdf', [ '--margin-top', '10', '--margin-bottom', '10', tempFile, fOut ], false, on_error, @ return From 7e2a3c3e7ebfbc85fff40bb764262ca0e8af2c7c Mon Sep 17 00:00:00 2001 From: ryneeverett Date: Fri, 6 Jan 2017 19:05:46 -0500 Subject: [PATCH 3/5] Add option to pass wkhtmltopdf options. Fix #176. It seems that some time in the last couple years wkhtmltopdf's default margins were changed from '10mm' to zero. As an alternative to #177, this PR adds an option to pass in arbitrary wkhtmltopdf long arguments and sets the default top and bottom margin to '10mm'. --- README.md | 4 ++++ dist/generators/html-pdf-cli-generator.js | 18 +++++++++++++----- dist/verbs/build.js | 1 + src/generators/html-pdf-cli-generator.coffee | 17 +++++++++++++---- src/verbs/build.coffee | 1 + 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 989c078..93a7224 100644 --- a/README.md +++ b/README.md @@ -490,6 +490,10 @@ The options file can contain any documented HackMyResume option, including "sectionTitles": { "employment": "Work" } + // Change wkhtmltopdf margins + "wkhtmltopdf": { + "margin-top": "20mm" + } } ``` diff --git a/dist/generators/html-pdf-cli-generator.js b/dist/generators/html-pdf-cli-generator.js index c93aea2..8a81b6e 100644 --- a/dist/generators/html-pdf-cli-generator.js +++ b/dist/generators/html-pdf-cli-generator.js @@ -52,7 +52,7 @@ Definition of the HtmlPdfCLIGenerator class. } if (_.has(engines, safe_eng)) { this.errHandler = info.opts.errHandler; - engines[safe_eng].call(this, info.mk, info.outputFile, this.onError); + engines[safe_eng].call(this, info.mk, info.outputFile, info.opts, this.onError); return null; } }; @@ -86,11 +86,19 @@ Definition of the HtmlPdfCLIGenerator class. TODO: If HTML generation has run, reuse that output TODO: Local web server to ease wkhtmltopdf rendering */ - wkhtmltopdf: function(markup, fOut, on_error) { - var tempFile; + wkhtmltopdf: function(markup, fOut, opts, on_error) { + var tempFile, wkhtmltopdf_args, wkhtmltopdf_options; tempFile = fOut.replace(/\.pdf$/i, '.pdf.html'); FS.writeFileSync(tempFile, markup, 'utf8'); - SPAWN('wkhtmltopdf', [tempFile, fOut], false, on_error, this); + wkhtmltopdf_options = _.extend({ + 'margin-bottom': '10mm', + 'margin-top': '10mm' + }, opts.wkhtmltopdf); + wkhtmltopdf_options = _.flatten(_.map(wkhtmltopdf_options, function(v, k) { + return ['--' + k, v]; + })); + wkhtmltopdf_args = wkhtmltopdf_options.concat([tempFile, fOut]); + SPAWN('wkhtmltopdf', wkhtmltopdf_args, false, on_error, this); }, /** @@ -100,7 +108,7 @@ Definition of the HtmlPdfCLIGenerator class. TODO: If HTML generation has run, reuse that output TODO: Local web server to ease Phantom rendering */ - phantomjs: function(markup, fOut, on_error) { + phantomjs: function(markup, fOut, opts, on_error) { var destPath, scriptPath, sourcePath, tempFile; tempFile = fOut.replace(/\.pdf$/i, '.pdf.html'); FS.writeFileSync(tempFile, markup, 'utf8'); diff --git a/dist/verbs/build.js b/dist/verbs/build.js index 2220acd..6db2476 100644 --- a/dist/verbs/build.js +++ b/dist/verbs/build.js @@ -242,6 +242,7 @@ Implementation of the 'build' verb for HackMyResume. _opts.noTips = opts.noTips; _opts.debug = opts.debug; _opts.sort = opts.sort; + _opts.wkhtmltopdf = opts.wkhtmltopdf; that = this; _opts.onTransform = function(info) { that.stat(HMEVENT.afterTransform, info); diff --git a/src/generators/html-pdf-cli-generator.coffee b/src/generators/html-pdf-cli-generator.coffee index 29884af..1912384 100644 --- a/src/generators/html-pdf-cli-generator.coffee +++ b/src/generators/html-pdf-cli-generator.coffee @@ -37,7 +37,7 @@ module.exports = class HtmlPdfCLIGenerator extends TemplateGenerator safe_eng = 'phantomjs' if safe_eng == 'phantom' if _.has engines, safe_eng @errHandler = info.opts.errHandler - engines[ safe_eng ].call @, info.mk, info.outputFile, @onError + engines[ safe_eng ].call @, info.mk, info.outputFile, info.opts, @onError return null # halt further processing @@ -64,11 +64,20 @@ engines = TODO: If HTML generation has run, reuse that output TODO: Local web server to ease wkhtmltopdf rendering ### - wkhtmltopdf: (markup, fOut, on_error) -> + wkhtmltopdf: (markup, fOut, opts, on_error) -> # Save the markup to a temporary file tempFile = fOut.replace /\.pdf$/i, '.pdf.html' FS.writeFileSync tempFile, markup, 'utf8' - SPAWN 'wkhtmltopdf', [ tempFile, fOut ], false, on_error, @ + + # Prepare wkhtmltopdf arguments. + wkhtmltopdf_options = _.extend( + {'margin-bottom': '10mm', 'margin-top': '10mm'}, opts.wkhtmltopdf) + wkhtmltopdf_options = _.flatten(_.map(wkhtmltopdf_options, (v, k)-> + return ['--' + k, v] + )) + wkhtmltopdf_args = wkhtmltopdf_options.concat [ tempFile, fOut ] + + SPAWN 'wkhtmltopdf', wkhtmltopdf_args , false, on_error, @ return @@ -80,7 +89,7 @@ engines = TODO: If HTML generation has run, reuse that output TODO: Local web server to ease Phantom rendering ### - phantomjs: ( markup, fOut, on_error ) -> + phantomjs: ( markup, fOut, opts, on_error ) -> # Save the markup to a temporary file tempFile = fOut.replace /\.pdf$/i, '.pdf.html' FS.writeFileSync tempFile, markup, 'utf8' diff --git a/src/verbs/build.coffee b/src/verbs/build.coffee index 1214da1..4d54dab 100644 --- a/src/verbs/build.coffee +++ b/src/verbs/build.coffee @@ -176,6 +176,7 @@ _prep = ( src, dst, opts ) -> _opts.noTips = opts.noTips _opts.debug = opts.debug _opts.sort = opts.sort + _opts.wkhtmltopdf = opts.wkhtmltopdf that = @ # Set up callbacks for internal generators From d31f6caf50a8361d494a9a7157f17316f4bd8b68 Mon Sep 17 00:00:00 2001 From: ryneeverett Date: Fri, 6 Jan 2017 22:37:08 -0500 Subject: [PATCH 4/5] When date ranges are identical, only show one. --- dist/helpers/generic-helpers.js | 4 +++- src/helpers/generic-helpers.coffee | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dist/helpers/generic-helpers.js b/dist/helpers/generic-helpers.js index 6d65c56..a9da25e 100644 --- a/dist/helpers/generic-helpers.js +++ b/dist/helpers/generic-helpers.js @@ -589,7 +589,9 @@ Generic template helper definitions for HackMyResume / FluentCV. dateTemp = FluentDate.fmt(dateB); dateTo = dateTemp.format(fmt); } - if (dateFrom && dateTo) { + if (dateFrom === dateTo) { + return dateFrom; + } else if (dateFrom && dateTo) { return dateFrom + sep + dateTo; } else if (dateFrom || dateTo) { return dateFrom || dateTo; diff --git a/src/helpers/generic-helpers.coffee b/src/helpers/generic-helpers.coffee index 242c4fc..dddef4d 100644 --- a/src/helpers/generic-helpers.coffee +++ b/src/helpers/generic-helpers.coffee @@ -551,7 +551,10 @@ _fromTo = ( dateA, dateB, fmt, sep, fallback ) -> dateTemp = FluentDate.fmt( dateB ) dateTo = dateTemp.format( fmt ) - if dateFrom && dateTo + + if dateFrom == dateTo + return dateFrom + else if dateFrom && dateTo return dateFrom + sep + dateTo else if dateFrom || dateTo return dateFrom || dateTo From 419c935d824bdc059e4cff0fa7d7c83941554a12 Mon Sep 17 00:00:00 2001 From: ryneeverett Date: Mon, 16 Jan 2017 00:15:04 -0500 Subject: [PATCH 5/5] Add weasyprint pdf generator support. Note: This is based off because I changed the generator expected arguments in that branch. --- README.md | 12 ++++++++---- dist/generators/html-pdf-cli-generator.js | 13 +++++++++++++ src/generators/html-pdf-cli-generator.coffee | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 93a7224..35d9fa7 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ Alternately, install the latest bleeding-edge version (updated daily): HackMyResume tries not to impose a specific PDF engine requirement on the user, but will instead work with whatever PDF engines you have installed. -Currently, HackMyResume's PDF generation requires either [Phantom.js][2] or -[wkhtmltopdf][3] to be installed on your system and the `phantomjs` and/or -`wkhtmltopdf` binaries to be accessible on your PATH. This is an optional +Currently, HackMyResume's PDF generation requires either [Phantom.js][2], +[wkhtmltopdf][3], or [WeasyPrint][11] to be installed on your system and the +corresponding binary to be accessible on your PATH. This is an optional requirement for users who care about PDF formats. If you don't care about PDF formats, skip this step. @@ -320,7 +320,8 @@ PDF engine you have installed through the engine's command-line interface (CLI). Currently that means one or both of... - [wkhtmltopdf][3] -- [Phantom.js][3] +- [Phantom.js][2] +- [WeasyPrint][11] ..with support for other engines planned in the future. But for now, **one or both of these engines must be installed and accessible on your PATH in order to @@ -330,6 +331,7 @@ invoke either of these tools directly from your shell or terminal without error: ```bash wkhtmltopdf input.html output.pdf phantomjs script.js input.html output.pdf +weasyprint input.html output.pdf ``` Assuming you've installed one or both of these engines on your system, you can @@ -339,6 +341,7 @@ tell HackMyResume which flavor of PDF generation to use via the `--pdf` option ```bash hackmyresume BUILD resume.json TO out.all --pdf phantom hackmyresume BUILD resume.json TO out.all --pdf wkhtmltopdf +hackmyresume BUILD resume.json TO out.all --pdf weasyprint hackmyresume BUILD resume.json TO out.all --pdf none ``` @@ -558,6 +561,7 @@ MIT. Go crazy. See [LICENSE.md][1] for details. [8]: https://youtu.be/N9wsjroVlu8 [9]: https://api.jquery.com/jquery.extend/ [10]: https://github.com/beautify-web/js-beautify +[11]: http://weasyprint.org/ [fresh]: https://github.com/fluentdesk/FRESH [fresca]: https://github.com/fluentdesk/FRESCA [dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself diff --git a/dist/generators/html-pdf-cli-generator.js b/dist/generators/html-pdf-cli-generator.js index 8a81b6e..eb4692e 100644 --- a/dist/generators/html-pdf-cli-generator.js +++ b/dist/generators/html-pdf-cli-generator.js @@ -117,6 +117,19 @@ Definition of the HtmlPdfCLIGenerator class. sourcePath = SLASH(PATH.relative(process.cwd(), tempFile)); destPath = SLASH(PATH.relative(process.cwd(), fOut)); SPAWN('phantomjs', [scriptPath, sourcePath, destPath], false, on_error, this); + }, + + /** + Generate a PDF from HTML using WeasyPrint's CLI interface. + Spawns a child process with `weasyprint `. Weasy Print + must be installed and path-accessible. + TODO: If HTML generation has run, reuse that output + */ + weasyprint: function(markup, fOut, opts, on_error) { + var tempFile; + tempFile = fOut.replace(/\.pdf$/i, '.pdf.html'); + FS.writeFileSync(tempFile, markup, 'utf8'); + SPAWN('weasyprint', [tempFile, fOut], false, on_error, this); } }; diff --git a/src/generators/html-pdf-cli-generator.coffee b/src/generators/html-pdf-cli-generator.coffee index 1912384..15a7edd 100644 --- a/src/generators/html-pdf-cli-generator.coffee +++ b/src/generators/html-pdf-cli-generator.coffee @@ -99,3 +99,17 @@ engines = destPath = SLASH PATH.relative( process.cwd(), fOut) SPAWN 'phantomjs', [ scriptPath, sourcePath, destPath ], false, on_error, @ return + + ###* + Generate a PDF from HTML using WeasyPrint's CLI interface. + Spawns a child process with `weasyprint `. Weasy Print + must be installed and path-accessible. + TODO: If HTML generation has run, reuse that output + ### + weasyprint: ( markup, fOut, opts, on_error ) -> + # Save the markup to a temporary file + tempFile = fOut.replace /\.pdf$/i, '.pdf.html' + FS.writeFileSync tempFile, markup, 'utf8' + + SPAWN 'weasyprint', [tempFile, fOut], false, on_error, @ + return