Ebook Viewer: When viewing PDF run through OEBBook

This commit is contained in:
Kovid Goyal 2009-05-25 13:52:43 -07:00
parent 61b10c93d7
commit b407fdf9ab
2 changed files with 5 additions and 11 deletions

View File

@ -123,19 +123,21 @@ class EbookIterator(object):
self.delete_on_exit = []
self._tdir = TemporaryDirectory('_ebook_iter')
self.base = self._tdir.__enter__()
from calibre.ebooks.conversion.plumber import Plumber
from calibre.ebooks.conversion.plumber import Plumber, create_oebbook
plumber = Plumber(self.pathtoebook, self.base, self.log)
plumber.setup_options()
if hasattr(plumber.opts, 'dont_package'):
plumber.opts.dont_package = True
if hasattr(plumber.opts, 'no_process'):
plumber.opts.no_process = True
if hasattr(plumber.input_plugin, '_preprocess_html_for_viewer'):
plumber.input_plugin._preprocess_html_for_viewer = True
self.pathtoopf = plumber.input_plugin(open(plumber.input, 'rb'),
plumber.opts, plumber.input_fmt, self.log,
{}, self.base)
if plumber.input_fmt.lower() == 'pdf':
self.pathtoopf = create_oebbook(self.log, self.pathtoopf, plumber.opts,
plumber.input_plugin)
if hasattr(self.pathtoopf, 'manifest'):
self.pathtoopf = write_oebbook(self.pathtoopf, self.base)

View File

@ -17,18 +17,10 @@ class PDFInput(InputFormatPlugin):
description = 'Convert PDF files to HTML'
file_types = set(['pdf'])
_preprocess_html_for_viewer = False
def convert(self, stream, options, file_ext, log,
accelerators):
html = pdftohtml(stream.name)
if self._preprocess_html_for_viewer:
from calibre.ebooks.conversion.preprocess import HTMLPreProcessor
prepro = HTMLPreProcessor(lambda x:x, False)
html = prepro(html.decode('utf-8')).encode('utf-8')
with open('index.html', 'wb') as index:
index.write(html)