mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make blank page removal in PDF Output a little more robust
This commit is contained in:
parent
62edaf9a23
commit
3251d1d6ed
@ -61,7 +61,7 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
|
|
||||||
# Remove page-break-before on <body> element as it causes
|
# Remove page-break-before on <body> element as it causes
|
||||||
# blank pages in PDF Output
|
# blank pages in PDF Output
|
||||||
from calibre.ebooks.oeb.base import OEB_STYLES
|
from calibre.ebooks.oeb.base import OEB_STYLES, XPath
|
||||||
stylesheet = None
|
stylesheet = None
|
||||||
for item in self.oeb.manifest:
|
for item in self.oeb.manifest:
|
||||||
if item.media_type.lower() in OEB_STYLES:
|
if item.media_type.lower() in OEB_STYLES:
|
||||||
@ -69,8 +69,15 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
break
|
break
|
||||||
if stylesheet is not None:
|
if stylesheet is not None:
|
||||||
from cssutils.css import CSSRule
|
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):
|
for rule in stylesheet.data.cssRules.rulesOfType(CSSRule.STYLE_RULE):
|
||||||
if rule.selectorList.selectorText == '.calibre':
|
if rule.selectorList.selectorText in classes:
|
||||||
rule.style.removeProperty('page-break-before')
|
rule.style.removeProperty('page-break-before')
|
||||||
rule.style.removeProperty('page-break-after')
|
rule.style.removeProperty('page-break-after')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user