From 5804d188d9267e968582d3e0e0482368dd77a41f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 11 Sep 2011 08:32:54 -0400 Subject: [PATCH 1/3] Fix for bug #846183: unhandled exception converting to PDF. --- src/calibre/ebooks/pdf/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index ebe6533419..ac3708ff47 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -202,7 +202,7 @@ class PDFWriter(QObject): # {{{ inputPDF = PdfFileReader(item_stream) for page in inputPDF.pages: outPDF.addPage(page) - outPDF.write(self.out_stream) + outPDF.write(self.out_stream) finally: self._delete_tmpdir() self.loop.exit(0) From f9a358f77041052253ef643cafe82f4a60f12b09 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 11 Sep 2011 08:50:41 -0400 Subject: [PATCH 2/3] Fix PDF output on OSX: Force the use of OSX's internal PDF engine instead of using Qt's. --- src/calibre/ebooks/pdf/writer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index ac3708ff47..fe095ad441 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -11,6 +11,7 @@ Write content to PDF. import os import shutil +from calibre import isosx from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ebooks.pdf.pageoptions import unit, paper_size, \ orientation @@ -164,6 +165,8 @@ class PDFWriter(QObject): # {{{ self.logger.debug('\tRendering item %s as %i.pdf' % (os.path.basename(str(self.view.url().toLocalFile())), len(self.combine_queue))) printer = get_pdf_printer(self.opts) printer.setOutputFileName(item_path) + if isosx: + printer.setOutputFormat(QPrinter.NativeFormat) self.view.print_(printer) printer.abort() self._render_book() From be691bf8fcfb6eb5a5c3d08d00c8076a1a1eb412 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 11 Sep 2011 11:12:21 -0400 Subject: [PATCH 3/3] Add more places to set the PDF engine for OS X. --- src/calibre/ebooks/pdf/writer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index fe095ad441..05d874c9c3 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -165,6 +165,10 @@ class PDFWriter(QObject): # {{{ self.logger.debug('\tRendering item %s as %i.pdf' % (os.path.basename(str(self.view.url().toLocalFile())), len(self.combine_queue))) printer = get_pdf_printer(self.opts) printer.setOutputFileName(item_path) + # We have to set the engine to Native on OS X after the call to set + # filename. Setting a filename with .pdf as the extension causes + # Qt to set the format to use Qt's PDF engine even if native was + # previously set on the printer. if isosx: printer.setOutputFormat(QPrinter.NativeFormat) self.view.print_(printer) @@ -182,6 +186,8 @@ class PDFWriter(QObject): # {{{ item_path = os.path.join(self.tmp_path, 'cover.pdf') printer = get_pdf_printer(self.opts) printer.setOutputFileName(item_path) + if isosx: + printer.setOutputFormat(QPrinter.NativeFormat) self.combine_queue.insert(0, item_path) p = QPixmap() p.loadFromData(self.cover_data) @@ -232,6 +238,8 @@ class ImagePDFWriter(object): def render_images(self, outpath, mi, items): printer = get_pdf_printer(self.opts, for_comic=True) printer.setOutputFileName(outpath) + if isosx: + printer.setOutputFormat(QPrinter.NativeFormat) printer.setDocName(mi.title) printer.setCreator(u'%s [%s]'%(__appname__, __version__)) # Seems to be no way to set author