From ddc72ff5db3de291d66a497883cbef2375ca068d Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:22:16 +0200 Subject: [PATCH] Added support for CSS page break properties + bugfixes (#1209) --- CHANGELOG.md | 19 +++--- README.md | 2 +- docs/Development.md | 8 +++ docs/HTML.md | 19 +++++- docs/Shapes.md | 2 + docs/Tables.md | 2 + docs/Templates.md | 1 + docs/Text.md | 3 +- docs/TextStyling.md | 14 +++-- docs/index.md | 2 +- fpdf/fpdf.py | 32 +++++++--- fpdf/html.py | 54 +++++++++++----- scripts/changed_pdfs_comparison.html | 6 +- scripts/compare-changed-pdfs.py | 6 +- scripts/pdfchecker.py | 3 + test/html/html_features.pdf | Bin 6323 -> 6742 bytes ...ght_at_page_bottom_triggers_page_break.pdf | Bin 0 -> 2650 bytes test/html/html_page_break_after.pdf | Bin 0 -> 1810 bytes test/html/html_page_break_before.pdf | Bin 0 -> 1819 bytes ...th_multiline_cells_and_split_over_page.pdf | Bin 3183 -> 3167 bytes test/html/test_html.py | 59 +++++++++++++++--- ...l_context_font_size_and_header_footer.pdf} | Bin 1546 -> 1534 bytes test/outline/html_toc.pdf | Bin 4312 -> 4304 bytes test/outline/html_toc_2_pages.pdf | Bin 20920 -> 20885 bytes .../html_toc_with_custom_rendering.pdf | Bin 2476 -> 2471 bytes .../html_toc_with_h1_as_2nd_heading.pdf | Bin 2850 -> 2845 bytes test/test_graphics_context.py | 23 ++++++- test/text/test_cell.py | 21 ------- 28 files changed, 200 insertions(+), 76 deletions(-) create mode 100644 test/html/html_img_without_height_at_page_bottom_triggers_page_break.pdf create mode 100644 test/html/html_page_break_after.pdf create mode 100644 test/html/html_page_break_before.pdf rename test/{text/header_footer_and_local_context_font_size.pdf => local_context_font_size_and_header_footer.pdf} (81%) diff --git a/CHANGELOG.md b/CHANGELOG.md index de0f49290..5f8717543 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,19 +19,21 @@ This can also be enabled programmatically with `warnings.simplefilter('default', ## [2.7.10] - Not released yet ### Added * [`Templates`](https://py-pdf.github.io/fpdf2/fpdf/Templates.html) can now be also defined in JSON files. -* support to optionally set `wrapmode` in templates (default `"WORD"` can optionally be set to `"CHAR"` to support wrapping on characters for scripts like Chinese or Japanese) - _cf._ [#1159](https://github.com/py-pdf/fpdf2/issues/1159) -* support for quadratic and cubic Bézier curves with [`FPDF.bezier()`](https://py-pdf.github.io/fpdf2/fpdf/Shapes.html#fpdf.fpdf.FPDF.bezier) -* feature to identify the Unicode script of the input text and break it into fragments when different scripts are used, improving text shaping results +* support to optionally set `wrapmode` in templates (default `"WORD"` can optionally be set to `"CHAR"` to support wrapping on characters for scripts like Chinese or Japanese) - _cf._ [#1159](https://github.com/py-pdf/fpdf2/issues/1159) - thanks to @carlhiggs +* support for quadratic and cubic Bézier curves with [`FPDF.bezier()`](https://py-pdf.github.io/fpdf2/fpdf/Shapes.html#fpdf.fpdf.FPDF.bezier) - thanks to @awmc000 +* feature to identify the Unicode script of the input text and break it into fragments when different scripts are used, improving [text shaping](https://py-pdf.github.io/fpdf2/TextShaping.html) results * [`FPDF.image()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.image): now handles `keep_aspect_ratio` in combination with an enum value provided to `x` * file names are mentioned in errors when `fpdf2` fails to parse a SVG image -* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): spacing before lists can now be adjusted via the `HTML2FPDF.list_vertical_margin` attribute +* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): now supports CSS page breaks properties : [documentation](https://py-pdf.github.io/fpdf2/HTML.html#page-breaks) +* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): spacing before lists can now be adjusted via the `HTML2FPDF.list_vertical_margin` attribute - thanks to @lcgeneralprojects ### Fixed * [`FPDF.local_context()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.local_context) used to leak styling during page breaks, when rendering `footer()` & `header()` * [`fpdf.drawing.DeviceCMYK`](https://py-pdf.github.io/fpdf2/fpdf/drawing.html#fpdf.drawing.DeviceCMYK) objects can now be passed to [`FPDF.set_draw_color()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.set_draw_color), [`FPDF.set_fill_color()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.set_fill_color) and [`FPDF.set_text_color()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.set_text_color) without raising a `ValueError`: [documentation](https://py-pdf.github.io/fpdf2/Text.html#text-formatting). * [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): fixing rendering of `
` tags, that do not trigger a page break anymore +* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): fixed automatic page break when an image does not have enough vertical space to be rendered on a page * individual `/Resources` directories are now properly created for each document page. This change ensures better compliance with the PDF specification but results in a slight increase in the size of PDF documents. You can still use the old behavior by setting `FPDF().single_resources_object = True` -* line size calculation for fragments when text shaping is used -* fixed incoherent indentation of long list entries - _cf._ [issue #1073](https://github.com/py-pdf/fpdf2/issues/1073) +* line size calculation for fragments when [text shaping](https://py-pdf.github.io/fpdf2/TextShaping.html) is used +* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): fixed incoherent indentation of long `