diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index e68b6b80a8..f52c42811b 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -293,6 +293,7 @@ from calibre.ebooks.epub.output import EPUBOutput from calibre.ebooks.txt.output import TXTOutput from calibre.ebooks.pdf.output import PDFOutput from calibre.ebooks.pml.input import PMLInput +from calibre.ebooks.pml.output import PMLOutput from calibre.customize.profiles import input_profiles, output_profiles from calibre.devices.prs500.driver import PRS500 @@ -307,7 +308,8 @@ from calibre.devices.jetbook.driver import JETBOOK plugins = [HTML2ZIP, EPUBInput, MOBIInput, PDBInput, PDFInput, HTMLInput, TXTInput, OEBOutput, TXTOutput, PDFOutput, LITInput, ComicInput, - FB2Input, ODTInput, RTFInput, EPUBOutput, RecipeInput, PMLInput] + FB2Input, ODTInput, RTFInput, EPUBOutput, RecipeInput, PMLInput, + PMLOutput] plugins += [PRS505, PRS700, CYBOOKG3, KINDLE, KINDLE2, BLACKBERRY, EB600, \ JETBOOK] plugins += [x for x in list(locals().values()) if isinstance(x, type) and \ diff --git a/src/calibre/ebooks/pdb/ereader/output.py b/src/calibre/ebooks/pdb/ereader/output.py index 4b188ae2f1..f217c04415 100644 --- a/src/calibre/ebooks/pdb/ereader/output.py +++ b/src/calibre/ebooks/pdb/ereader/output.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/pdf/output.py b/src/calibre/ebooks/pdf/output.py index 3f1e2db907..4eb23877d9 100644 --- a/src/calibre/ebooks/pdf/output.py +++ b/src/calibre/ebooks/pdf/output.py @@ -63,8 +63,10 @@ class PDFOutput(OutputFormatPlugin): def convert_text(self, oeb_book): with TemporaryDirectory('_pdf_out') as oebdir: - OEBOutput(None).convert(oeb_book, oebdir, self.input_plugin, self.opts, self.log) - + from calibre.customize.ui import plugin_for_output_format + oeb_output = plugin_for_output_format('oeb') + oeb_output.convert(oeb, oeb_dir, self.input_plugin, self.opts, self.log) + opfpath = glob.glob(os.path.join(oebdir, '*.opf'))[0] opf = OPF(opfpath, os.path.dirname(opfpath)) diff --git a/src/calibre/ebooks/pml/output.py b/src/calibre/ebooks/pml/output.py new file mode 100644 index 0000000000..c5fbc990af --- /dev/null +++ b/src/calibre/ebooks/pml/output.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +import os + +import Image, cStringIO + +from calibre.customize.conversion import OutputFormatPlugin +from calibre.ptempfile import TemporaryDirectory +from calibre.utils.zipfile import ZipFile +from calibre.ebooks.oeb.base import OEB_IMAGES +from calibre.ebooks.pml.pmlconverter import html_to_pml + +class PMLOutput(OutputFormatPlugin): + + name = 'PML Output' + author = 'John Schember' + file_type = 'pmlz' + + def convert(self, oeb_book, output_path, input_plugin, opts, log): + with TemporaryDirectory('_pmlz_output') as tdir: + self.process_spine(oeb_book.spine, tdir) + self.write_images(oeb_book.manifest, tdir) + + pmlz = ZipFile(output_path, 'w') + pmlz.add_dir(tdir) + + def process_spine(self, spine, out_dir): + for item in spine: + html = html_to_pml(unicode(item)).encode('utf-8') + + name = os.path.splitext(os.path.basename(item.href))[0] + '.pml' + path = os.path.join(out_dir, name) + + with open(path, 'wb') as out: + out.write(html) + + def write_images(self, manifest, out_dir): + for item in manifest: + if item.media_type in OEB_IMAGES: + im = Image.open(cStringIO.StringIO(item.data)) + + data = cStringIO.StringIO() + im.save(data, 'PNG') + data = data.getvalue() + + name = os.path.splitext(os.path.basename(item.href))[0] + '.png' + path = os.path.join(out_dir, name) + + with open(path, 'wb') as out: + out.write(data) +