mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-03 12:57:08 +01: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:
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)) {
|
||||
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');
|
||||
|
Reference in New Issue
Block a user