From cc09af522e371caeff4a414647ef1a1f2db36ce9 Mon Sep 17 00:00:00 2001 From: Charles Low Date: Mon, 4 Nov 2024 01:14:19 -0800 Subject: [PATCH] add pagebreak support --- htmldocx/h2d.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htmldocx/h2d.py b/htmldocx/h2d.py index 6a0e113..b7e7569 100644 --- a/htmldocx/h2d.py +++ b/htmldocx/h2d.py @@ -226,6 +226,7 @@ def add_styles_to_paragraph(self, style): self.paragraph.paragraph_format.left_indent = Inches(min(margin // 10 * INDENT, MAX_INDENT)) # TODO handle non px units + def add_styles_to_run(self, style): if 'color' in style: if 'rgb' in style['color']: @@ -399,6 +400,9 @@ def handle_link(self, href, text): # Add hyperlink to run self.paragraph._p.append(hyperlink) + def handle_pagebreak(self): + self.doc.add_page_break() + def handle_starttag(self, tag, attrs): if self.skip: return @@ -468,6 +472,13 @@ def handle_starttag(self, tag, attrs): elif tag == 'table': self.handle_table() return + # handle pagebreak using following html code + #
+ elif tag == 'div': + style = self.parse_dict_string(current_attrs['style']) + if(style.get('page-break-after', '') == 'always'): + self.handle_pagebreak() + # set new run reference point in case of leading line breaks if tag in ['p', 'li', 'pre']: