1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-03 04:47:07 +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:
ryneeverett
2017-01-06 19:05:46 -05:00
parent 3cf850ea0e
commit 7e2a3c3e7e
5 changed files with 32 additions and 9 deletions

View File

@ -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'

View File

@ -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