From a0da923c093f79e2205529c5f12fad620f3159a7 Mon Sep 17 00:00:00 2001 From: Simon Law Date: Tue, 24 Jul 2012 16:18:39 -0400 Subject: PDFTemplateView.cmd_options contains all the options to pass to wkhtmltopdf Before, command-line arguments were class-based. Unfortunately, this means that you cannot add new command-line arguments without subclassing. Instead, PDFTemplateView.cmd_options is a dictionary of all command-line arguments. PDFTemplateView.as_view(cmd_options={...}) now works as expected. !!!! WARNING !!!! cmd_options is now empty, leaving wkhtmltopdf with its default behaviour. Explicitly add the options you want. Existing subclasses of PDFTemplateView will now break, but a PendingDeprecationWarning will be issued. Margins will now be wkhtmltopdf's default of 10mm. PdfTemplateView contains a compatibility shim with the old default values for margins and orientation. --- wkhtmltopdf/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'wkhtmltopdf/utils.py') diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index d0475c4..03a5f82 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -19,6 +19,8 @@ def _options_to_args(**options): flags = [] for name in sorted(options): value = options[name] + if value is None: + continue flags.append('--' + name.replace('_', '-')) if value is not True: flags.append(unicode(value)) @@ -38,11 +40,17 @@ def wkhtmltopdf(pages, output=None, **kwargs): {'footer_html': 'http://example.com/foot.html'} becomes '--footer-html http://example.com/foot.html' + Where there is no value passed, use True. e.g.: {'disable_javascript': True} becomes: '--disable-javascript' + To disable a default option, use None. e.g: + {'quiet': None'} + becomes: + '' + example usage: wkhtmltopdf(pages=['/tmp/example.html'], dpi=300, -- cgit v1.2.3