diff --git a/src/calibre/ebooks/pdf/output.py b/src/calibre/ebooks/pdf/output.py index 7b8b0323ab..a2674b83eb 100644 --- a/src/calibre/ebooks/pdf/output.py +++ b/src/calibre/ebooks/pdf/output.py @@ -28,23 +28,11 @@ class PDFOutput(OutputFormatPlugin): file_type = 'pdf' options = set([ - OptionRecommendation(name='margin_top', recommended_value='1', - level=OptionRecommendation.LOW, - help=_('The top margin around the document.')), - OptionRecommendation(name='margin_bottom', recommended_value='1', - level=OptionRecommendation.LOW, - help=_('The bottom margin around the document.')), - OptionRecommendation(name='margin_left', recommended_value='1', - level=OptionRecommendation.LOW, - help=_('The left margin around the document.')), - OptionRecommendation(name='margin_right', recommended_value='1', - level=OptionRecommendation.LOW, - help=_('The right margin around the document.')), - OptionRecommendation(name='unit', recommended_value='inch', level=OptionRecommendation.LOW, short_switch='u', choices=UNITS.keys(), help=_('The unit of measure. Default is inch. Choices ' - 'are %s' % UNITS.keys())), + 'are %s ' + 'Note: This does not override the unit for margins!' % UNITS.keys())), OptionRecommendation(name='paper_size', recommended_value='letter', level=OptionRecommendation.LOW, choices=PAPER_SIZES.keys(), help=_('The size of the paper. Default is letter. Choices ' @@ -60,15 +48,23 @@ class PDFOutput(OutputFormatPlugin): ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): - self.opts, self.log = opts, log + self.input_plugin, self.opts, self.log = input_plugin, opts, log + if input_plugin.is_image_collection: - self.convert_images(input_plugin.get_images()) + self.convert_images(input_plugin.get_images(), output_path) + else: + self.convert_text(oeb_book, output_path) + + def convert_images(self, images, output_path): + raise NotImplementedError() + + def convert_text(self, oeb_book, output_path): with TemporaryDirectory('_pdf_out') as oebdir: - OEBOutput(None).convert(oeb_book, oebdir, input_plugin, opts, log) + OEBOutput(None).convert(oeb_book, oebdir, self.input_plugin, self.opts, self.log) opf = glob.glob(os.path.join(oebdir, '*.opf'))[0] - writer = PDFWriter(log, opts) + writer = PDFWriter(self.opts, self.log) close = False if not hasattr(output_path, 'write'): @@ -85,3 +81,4 @@ class PDFOutput(OutputFormatPlugin): if close: out_stream.close() + diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index 7a9973c6d7..e82c6bd257 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -37,7 +37,7 @@ class PDFMetadata(object): class PDFWriter(QObject): - def __init__(self, log, opts): + def __init__(self, opts, log): if QApplication.instance() is None: QApplication([]) QObject.__init__(self) @@ -107,7 +107,7 @@ class PDFWriter(QObject): else: printer.setPaperSize(QSizeF(self.opts.output_profile.width / self.opts.output_profile.dpi, self.opts.output_profile.height / self.opts.output_profile.dpi), QPrinter.Inch) - printer.setPageMargins(size(self.opts.margin_left), size(self.opts.margin_top), size(self.opts.margin_right), size(self.opts.margin_bottom), unit(self.opts.unit)) + printer.setPageMargins(0, 0, 0, 0, QPrinter.Point) printer.setOrientation(orientation(self.opts.orientation)) printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(item_path) @@ -132,3 +132,10 @@ class PDFWriter(QObject): finally: self._delete_tmpdir() self.loop.exit(0) + + +class ImagePDFWriter(object): + + def __init__(self, opts, log): + self.opts, self.log = opts, log +