From 3251d1d6ed05fe0cbc1a269d3cdc861dccd6d56d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 29 Jul 2010 15:32:31 -0600 Subject: [PATCH] Make blank page removal in PDF Output a little more robust --- src/calibre/ebooks/pdf/output.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/pdf/output.py b/src/calibre/ebooks/pdf/output.py index 9bceae0618..a395cdd847 100644 --- a/src/calibre/ebooks/pdf/output.py +++ b/src/calibre/ebooks/pdf/output.py @@ -61,7 +61,7 @@ class PDFOutput(OutputFormatPlugin): # Remove page-break-before on element as it causes # blank pages in PDF Output - from calibre.ebooks.oeb.base import OEB_STYLES + from calibre.ebooks.oeb.base import OEB_STYLES, XPath stylesheet = None for item in self.oeb.manifest: if item.media_type.lower() in OEB_STYLES: @@ -69,8 +69,15 @@ class PDFOutput(OutputFormatPlugin): break 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 == '.calibre': + if rule.selectorList.selectorText in classes: rule.style.removeProperty('page-break-before') rule.style.removeProperty('page-break-after')