mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
PDF Output: Use the cover from the input document when no cover is specified during a conversion
This commit is contained in:
parent
4fffee635a
commit
18f346d273
@ -97,24 +97,6 @@ class PDFOutput(OutputFormatPlugin):
|
||||
self.metadata = oeb_book.metadata
|
||||
self.cover_data = None
|
||||
|
||||
# Remove page-break-before on <body> element as it causes
|
||||
# blank pages in PDF Output
|
||||
from calibre.ebooks.oeb.base import XPath
|
||||
stylesheet = self.oeb.manifest.main_stylesheet
|
||||
if stylesheet is not None:
|
||||
from cssutils.css import CSSRule
|
||||
classes = set(['.calibre'])
|
||||
for x in self.oeb.spine:
|
||||
root = x.data
|
||||
body = XPath('//h:body[@class]')(root)
|
||||
if body:
|
||||
classes.add('.'+body[0].get('class'))
|
||||
|
||||
for rule in stylesheet.data.cssRules.rulesOfType(CSSRule.STYLE_RULE):
|
||||
if rule.selectorList.selectorText in classes:
|
||||
rule.style.removeProperty('page-break-before')
|
||||
rule.style.removeProperty('page-break-after')
|
||||
|
||||
|
||||
if input_plugin.is_image_collection:
|
||||
log.debug('Converting input as an image collection...')
|
||||
@ -128,16 +110,12 @@ class PDFOutput(OutputFormatPlugin):
|
||||
self.write(ImagePDFWriter, images)
|
||||
|
||||
def get_cover_data(self):
|
||||
g, m = self.oeb.guide, self.oeb.manifest
|
||||
if 'titlepage' not in g:
|
||||
if 'cover' in g:
|
||||
href = g['cover'].href
|
||||
from calibre.ebooks.oeb.base import urlnormalize
|
||||
for item in m:
|
||||
if item.href == urlnormalize(href):
|
||||
self.cover_data = item.data
|
||||
if not isinstance(self.cover_data, basestring):
|
||||
self.cover_data = None
|
||||
oeb = self.oeb
|
||||
if (oeb.metadata.cover and
|
||||
unicode(oeb.metadata.cover[0]) in oeb.manifest.ids):
|
||||
cover_id = unicode(oeb.metadata.cover[0])
|
||||
item = oeb.manifest.ids[cover_id]
|
||||
self.cover_data = item.data
|
||||
|
||||
def convert_text(self, oeb_book):
|
||||
from calibre.ebooks.pdf.writer import PDFWriter
|
||||
|
Loading…
x
Reference in New Issue
Block a user