mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -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.metadata = oeb_book.metadata
|
||||||
self.cover_data = None
|
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:
|
if input_plugin.is_image_collection:
|
||||||
log.debug('Converting input as an image collection...')
|
log.debug('Converting input as an image collection...')
|
||||||
@ -128,16 +110,12 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
self.write(ImagePDFWriter, images)
|
self.write(ImagePDFWriter, images)
|
||||||
|
|
||||||
def get_cover_data(self):
|
def get_cover_data(self):
|
||||||
g, m = self.oeb.guide, self.oeb.manifest
|
oeb = self.oeb
|
||||||
if 'titlepage' not in g:
|
if (oeb.metadata.cover and
|
||||||
if 'cover' in g:
|
unicode(oeb.metadata.cover[0]) in oeb.manifest.ids):
|
||||||
href = g['cover'].href
|
cover_id = unicode(oeb.metadata.cover[0])
|
||||||
from calibre.ebooks.oeb.base import urlnormalize
|
item = oeb.manifest.ids[cover_id]
|
||||||
for item in m:
|
self.cover_data = item.data
|
||||||
if item.href == urlnormalize(href):
|
|
||||||
self.cover_data = item.data
|
|
||||||
if not isinstance(self.cover_data, basestring):
|
|
||||||
self.cover_data = None
|
|
||||||
|
|
||||||
def convert_text(self, oeb_book):
|
def convert_text(self, oeb_book):
|
||||||
from calibre.ebooks.pdf.writer import PDFWriter
|
from calibre.ebooks.pdf.writer import PDFWriter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user