From b7dfad3f187305da4ca001a00da40525205d633f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 22 Apr 2012 20:55:50 -0400 Subject: [PATCH] PDF Output: Set engine on OS X based upon paper size as stanard sizes are fixed with Qt 4.8.1. Custom sizes are still broken. --- src/calibre/ebooks/pdf/writer.py | 41 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index a680d61188..ea23a9c248 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -45,29 +45,24 @@ def get_pdf_printer(opts, for_comic=False, output_file_name=None): if not is_ok_to_use_qt(): raise Exception('Not OK to use Qt') + custom_size = False printer = QPrinter(QPrinter.HighResolution) custom_size = get_custom_size(opts) - if isosx and not for_comic: - # On OSX, the native engine can only produce a single page size - # (usually A4). The Qt engine on the other hand produces image based - # PDFs. If we set a custom page size using QSizeF the native engine - # produces unreadable output, so we just ignore the custom size - # settings. - printer.setPaperSize(paper_size(opts.paper_size)) - else: - if opts.output_profile.short_name == 'default' or \ - opts.output_profile.width > 9999: - if custom_size is None: - printer.setPaperSize(paper_size(opts.paper_size)) - else: - printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]), unit(opts.unit)) + if opts.output_profile.short_name == 'default' or \ + opts.output_profile.width > 9999: + if custom_size is None: + printer.setPaperSize(paper_size(opts.paper_size)) else: - w = opts.output_profile.comic_screen_size[0] if for_comic else \ - opts.output_profile.width - h = opts.output_profile.comic_screen_size[1] if for_comic else \ - opts.output_profile.height - dpi = opts.output_profile.dpi - printer.setPaperSize(QSizeF(float(w) / dpi, float(h) / dpi), QPrinter.Inch) + custom_size = True + printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]), unit(opts.unit)) + else: + custom_size = True + w = opts.output_profile.comic_screen_size[0] if for_comic else \ + opts.output_profile.width + h = opts.output_profile.comic_screen_size[1] if for_comic else \ + opts.output_profile.height + dpi = opts.output_profile.dpi + printer.setPaperSize(QSizeF(float(w) / dpi, float(h) / dpi), QPrinter.Inch) if for_comic: # Comic pages typically have their own margins, or their background @@ -77,13 +72,13 @@ def get_pdf_printer(opts, for_comic=False, output_file_name=None): printer.setPageMargins(opts.margin_left, opts.margin_top, opts.margin_right, opts.margin_bottom, QPrinter.Point) printer.setOrientation(orientation(opts.orientation)) - printer.setOutputFormat(QPrinter.PdfFormat) printer.setFullPage(for_comic) if output_file_name: printer.setOutputFileName(output_file_name) - if isosx and not for_comic: - # Ensure we are not generating enormous image based PDFs + if isosx and not custom_size: printer.setOutputFormat(QPrinter.NativeFormat) + else: + printer.setOutputFormat(QPrinter.PdfFormat) return printer