Skip to content

Commit

Permalink
Fixing bgcolor usage in <table> - fix #512
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Sep 7, 2022
1 parent bbe3284 commit 356de1a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ This can also be enabled programmatically with `warnings.simplefilter('default',

### Fixed
- `arc()` not longer renders artefacts at intersection point, thanks to @Jmillan-Dev; [#488](https://github.com/PyFPDF/fpdf2/issues/488)
- [`write_html()`](https://pyfpdf.github.io/fpdf2/HTML.html): `<em>` & `<strong>` HTML tags are now properly supported - they were ignored previously; [#498](https://github.com/PyFPDF/fpdf2/issues/498)
- [`write_html()`](https://pyfpdf.github.io/fpdf2/HTML.html):
* `<em>` & `<strong>` HTML tags are now properly supported - they were ignored previously; [#498](https://github.com/PyFPDF/fpdf2/issues/498)
* `bgcolor` is not properly support in `<table>` tags; [#512](https://github.com/PyFPDF/fpdf2/issues/512)
- the `CreationDate` of PDFs & embedded files now includes the system timezone

### Added
Expand Down
2 changes: 1 addition & 1 deletion fpdf/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def box_shadow(self, w, h, bgcolor):
fill_color = self.pdf.fill_color
self.pdf.set_fill_color(*bgcolor)
self.pdf.rect(self.pdf.x, self.pdf.y, w, h, "F")
self.pdf.fill_color = fill_color
self.pdf.set_fill_color(*fill_color.colors)

def output_table_header(self):
if self.theader:
Expand Down
Binary file added test/html/bgcolor_in_table.pdf
Binary file not shown.
22 changes: 22 additions & 0 deletions test/html/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,25 @@ def test_html_custom_heading_sizes(tmp_path): # issue-223
heading_sizes=dict(h1=6, h2=12, h3=18, h4=24, h5=30, h6=36),
)
assert_pdf_equal(pdf, HERE / "html_custom_heading_sizes.pdf", tmp_path)


def test_bgcolor_in_table(tmp_path): # issue-512
pdf = MyFPDF()
pdf.add_page()
pdf.write_html(
"""<table>
<thead>
<tr>
<th width="25%">Career</th>
<th width="75%">Quote</th>
</tr>
</thead>
<tbody>
<tr bgcolor="grey"><td>Engineer</td><td>The engineer has been, and is, a maker of history.</td></tr>
<tr bgcolor="white"><td>Developer</td><td>Logical thinking, passion and perseverance is the paint on your palette.</td></tr>
<tr bgcolor="grey"><td>Analyst</td><td>Seeing what other people can't see gives you great vision.</td></tr>
<tr bgcolor="white"><td><i>None of the above</i></td><td>I'm sorry. We could not find a quote for your job.</td></tr>
</tbody>
</table>"""
)
assert_pdf_equal(pdf, HERE / "bgcolor_in_table.pdf", tmp_path)

0 comments on commit 356de1a

Please sign in to comment.