mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
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'.
This commit is contained in:
parent
3cf850ea0e
commit
7e2a3c3e7e
@ -490,6 +490,10 @@ The options file can contain any documented HackMyResume option, including
|
|||||||
"sectionTitles": {
|
"sectionTitles": {
|
||||||
"employment": "Work"
|
"employment": "Work"
|
||||||
}
|
}
|
||||||
|
// Change wkhtmltopdf margins
|
||||||
|
"wkhtmltopdf": {
|
||||||
|
"margin-top": "20mm"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
18
dist/generators/html-pdf-cli-generator.js
vendored
18
dist/generators/html-pdf-cli-generator.js
vendored
@ -52,7 +52,7 @@ Definition of the HtmlPdfCLIGenerator class.
|
|||||||
}
|
}
|
||||||
if (_.has(engines, safe_eng)) {
|
if (_.has(engines, safe_eng)) {
|
||||||
this.errHandler = info.opts.errHandler;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -86,11 +86,19 @@ Definition of the HtmlPdfCLIGenerator class.
|
|||||||
TODO: If HTML generation has run, reuse that output
|
TODO: If HTML generation has run, reuse that output
|
||||||
TODO: Local web server to ease wkhtmltopdf rendering
|
TODO: Local web server to ease wkhtmltopdf rendering
|
||||||
*/
|
*/
|
||||||
wkhtmltopdf: function(markup, fOut, on_error) {
|
wkhtmltopdf: function(markup, fOut, opts, on_error) {
|
||||||
var tempFile;
|
var tempFile, wkhtmltopdf_args, wkhtmltopdf_options;
|
||||||
tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
||||||
FS.writeFileSync(tempFile, markup, 'utf8');
|
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: If HTML generation has run, reuse that output
|
||||||
TODO: Local web server to ease Phantom rendering
|
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;
|
var destPath, scriptPath, sourcePath, tempFile;
|
||||||
tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
||||||
FS.writeFileSync(tempFile, markup, 'utf8');
|
FS.writeFileSync(tempFile, markup, 'utf8');
|
||||||
|
1
dist/verbs/build.js
vendored
1
dist/verbs/build.js
vendored
@ -242,6 +242,7 @@ Implementation of the 'build' verb for HackMyResume.
|
|||||||
_opts.noTips = opts.noTips;
|
_opts.noTips = opts.noTips;
|
||||||
_opts.debug = opts.debug;
|
_opts.debug = opts.debug;
|
||||||
_opts.sort = opts.sort;
|
_opts.sort = opts.sort;
|
||||||
|
_opts.wkhtmltopdf = opts.wkhtmltopdf;
|
||||||
that = this;
|
that = this;
|
||||||
_opts.onTransform = function(info) {
|
_opts.onTransform = function(info) {
|
||||||
that.stat(HMEVENT.afterTransform, info);
|
that.stat(HMEVENT.afterTransform, info);
|
||||||
|
@ -37,7 +37,7 @@ module.exports = class HtmlPdfCLIGenerator extends TemplateGenerator
|
|||||||
safe_eng = 'phantomjs' if safe_eng == 'phantom'
|
safe_eng = 'phantomjs' if safe_eng == 'phantom'
|
||||||
if _.has engines, safe_eng
|
if _.has engines, safe_eng
|
||||||
@errHandler = info.opts.errHandler
|
@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
|
return null # halt further processing
|
||||||
|
|
||||||
|
|
||||||
@ -64,11 +64,20 @@ engines =
|
|||||||
TODO: If HTML generation has run, reuse that output
|
TODO: If HTML generation has run, reuse that output
|
||||||
TODO: Local web server to ease wkhtmltopdf rendering
|
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
|
# Save the markup to a temporary file
|
||||||
tempFile = fOut.replace /\.pdf$/i, '.pdf.html'
|
tempFile = fOut.replace /\.pdf$/i, '.pdf.html'
|
||||||
FS.writeFileSync tempFile, markup, 'utf8'
|
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
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +89,7 @@ engines =
|
|||||||
TODO: If HTML generation has run, reuse that output
|
TODO: If HTML generation has run, reuse that output
|
||||||
TODO: Local web server to ease Phantom rendering
|
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
|
# Save the markup to a temporary file
|
||||||
tempFile = fOut.replace /\.pdf$/i, '.pdf.html'
|
tempFile = fOut.replace /\.pdf$/i, '.pdf.html'
|
||||||
FS.writeFileSync tempFile, markup, 'utf8'
|
FS.writeFileSync tempFile, markup, 'utf8'
|
||||||
|
@ -176,6 +176,7 @@ _prep = ( src, dst, opts ) ->
|
|||||||
_opts.noTips = opts.noTips
|
_opts.noTips = opts.noTips
|
||||||
_opts.debug = opts.debug
|
_opts.debug = opts.debug
|
||||||
_opts.sort = opts.sort
|
_opts.sort = opts.sort
|
||||||
|
_opts.wkhtmltopdf = opts.wkhtmltopdf
|
||||||
that = @
|
that = @
|
||||||
|
|
||||||
# Set up callbacks for internal generators
|
# Set up callbacks for internal generators
|
||||||
|
Loading…
Reference in New Issue
Block a user