home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1044 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.2 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL 3'
  5. __copyright__ = '2009, John Schember <john@nachtimwald.com>'
  6. __docformat__ = 'restructuredtext en'
  7. import os
  8. from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
  9. from calibre.ebooks.pdf.pdftohtml import pdftohtml
  10. from calibre.ebooks.metadata.opf2 import OPFCreator
  11. from calibre.constants import plugins
  12. (pdfreflow, pdfreflow_err) = plugins['pdfreflow']
  13.  
  14. class PDFInput(InputFormatPlugin):
  15.     name = 'PDF Input'
  16.     author = 'Kovid Goyal and John Schember'
  17.     description = 'Convert PDF files to HTML'
  18.     file_types = set([
  19.         'pdf'])
  20.     options = set([
  21.         OptionRecommendation(name = 'no_images', recommended_value = False, help = _('Do not extract images from the document')),
  22.         OptionRecommendation(name = 'unwrap_factor', recommended_value = 0.5, help = _('Scale used to determine the length at which a line should be unwrapped. Valid values are a decimal between 0 and 1. The default is 0.5, this is the median line length.')),
  23.         OptionRecommendation(name = 'new_pdf_engine', recommended_value = False, help = _('Use the new PDF conversion engine.'))])
  24.     
  25.     def convert_new(self, stream, accelerators):
  26.         PDFDocument = PDFDocument
  27.         import calibre.ebooks.pdf.reflow
  28.         if pdfreflow_err:
  29.             raise RuntimeError('Failed to load pdfreflow: ' + pdfreflow_err)
  30.         pdfreflow_err
  31.         pdfreflow.reflow(stream.read())
  32.         xml = open('index.xml', 'rb').read()
  33.         PDFDocument(xml, self.opts, self.log)
  34.         return os.path.join(os.getcwd(), 'metadata.opf')
  35.  
  36.     
  37.     def convert(self, stream, options, file_ext, log, accelerators):
  38.         log.debug('Converting file to html...')
  39.         self.opts = options
  40.         self.log = log
  41.         if options.new_pdf_engine:
  42.             return self.convert_new(stream, accelerators)
  43.         pdftohtml(os.getcwd(), stream.name, options.no_images)
  44.         get_metadata = get_metadata
  45.         import calibre.ebooks.metadata.meta
  46.         log.debug('Retrieving document metadata...')
  47.         mi = get_metadata(stream, 'pdf')
  48.         opf = OPFCreator(os.getcwd(), mi)
  49.         manifest = [
  50.             ('index.html', None)]
  51.         images = os.listdir(os.getcwd())
  52.         images.remove('index.html')
  53.         for i in images:
  54.             manifest.append((i, None))
  55.         
  56.         log.debug('Generating manifest...')
  57.         opf.create_manifest(manifest)
  58.         opf.create_spine([
  59.             'index.html'])
  60.         log.debug('Rendering manifest...')
  61.         
  62.         try:
  63.             opffile = _[1]
  64.             opf.render(opffile)
  65.         finally:
  66.             pass
  67.  
  68.         return os.path.join(os.getcwd(), 'metadata.opf')
  69.  
  70.  
  71.