Implement bug #4971: Support reading of PDF PDB files.

This commit is contained in:
John Schember 2010-02-21 10:48:24 -05:00
parent f1452adbed
commit 9c74cd945f
4 changed files with 42 additions and 2 deletions

View File

@ -177,7 +177,7 @@ class EbookIterator(object):
plumber.opts, plumber.input_fmt, self.log, plumber.opts, plumber.input_fmt, self.log,
{}, self.base) {}, self.base)
if processed or plumber.input_fmt.lower() in ('pdf', 'rb') and \ if processed or plumber.input_fmt.lower() in ('pdb', 'pdf', 'rb') and \
not hasattr(self.pathtoopf, 'manifest'): not hasattr(self.pathtoopf, 'manifest'):
self.pathtoopf = create_oebbook(self.log, self.pathtoopf, plumber.opts, self.pathtoopf = create_oebbook(self.log, self.pathtoopf, plumber.opts,
plumber.input_plugin) plumber.input_plugin)

View File

@ -11,12 +11,14 @@ class PDBError(Exception):
from calibre.ebooks.pdb.ereader.reader import Reader as ereader_reader from calibre.ebooks.pdb.ereader.reader import Reader as ereader_reader
from calibre.ebooks.pdb.palmdoc.reader import Reader as palmdoc_reader from calibre.ebooks.pdb.palmdoc.reader import Reader as palmdoc_reader
from calibre.ebooks.pdb.ztxt.reader import Reader as ztxt_reader from calibre.ebooks.pdb.ztxt.reader import Reader as ztxt_reader
from calibre.ebooks.pdb.pdf.reader import Reader as pdf_reader
FORMAT_READERS = { FORMAT_READERS = {
'PNPdPPrs': ereader_reader, 'PNPdPPrs': ereader_reader,
'PNRdPPrs': ereader_reader, 'PNRdPPrs': ereader_reader,
'zTXTGPlm': ztxt_reader, 'zTXTGPlm': ztxt_reader,
'TEXtREAd': palmdoc_reader, 'TEXtREAd': palmdoc_reader,
'.pdfADBE': pdf_reader,
} }
from calibre.ebooks.pdb.palmdoc.writer import Writer as palmdoc_writer from calibre.ebooks.pdb.palmdoc.writer import Writer as palmdoc_writer
@ -34,8 +36,8 @@ IDENTITY_TO_NAME = {
'PNRdPPrs': 'eReader', 'PNRdPPrs': 'eReader',
'zTXTGPlm': 'zTXT', 'zTXTGPlm': 'zTXT',
'TEXtREAd': 'PalmDOC', 'TEXtREAd': 'PalmDOC',
'.pdfADBE': 'Adobe Reader', '.pdfADBE': 'Adobe Reader',
'BVokBDIC': 'BDicty', 'BVokBDIC': 'BDicty',
'DB99DBOS': 'DB (Database program)', 'DB99DBOS': 'DB (Database program)',
'vIMGView': 'FireViewer (ImageViewer)', 'vIMGView': 'FireViewer (ImageViewer)',

View File

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
'''
Read content from palmdoc pdb file.
'''
__license__ = 'GPL v3'
__copyright__ = '2010, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import cStringIO
from calibre.ebooks.pdb.formatreader import FormatReader
from calibre.ptempfile import TemporaryFile
class Reader(FormatReader):
def __init__(self, header, stream, log, options):
self.header = header
self.stream = stream
self.log = log
self.options = options
setattr(self.options, 'new_pdf_engine', False)
setattr(self.options, 'no_images', False)
setattr(self.options, 'unwrap_factor', 0.5)
def extract_content(self, output_dir):
self.log.info('Extracting PDF...')
with TemporaryFile() as pdf_n:
pdf = open(pdf_n, 'rw+b')
for x in xrange(self.header.section_count()):
pdf.write(self.header.section_data(x))
from calibre.customize.ui import plugin_for_input_format
pdf.seek(0)
return plugin_for_input_format('pdf').convert(pdf, self.options,
'pdf', self.log, [])