Skip to content

set_page_background: raise a clear error for an invalid color - #2101

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:page-background-color
Nov 3, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:page-background-color

Conversation

@RavSinghChandan

Copy link
Copy Markdown

set_page_background() stored any tuple, and an invalid color only failed on the next add_page(), far from the call that set it:

  • (300, 0, 0) -> ValueError: color component 300 not in range [0, 255] from add_page()
  • (10, 20) -> ValueError: color component -1 not in range [0, 255], a value that was never passed
  • (10, 20, 30, 40) -> TypeError: FPDF.set_fill_color() takes from 2 to 4 positional arguments but 5 were given

A color tuple is now checked when it is set, like set_fill_color() checks its components: 1 (grey level) or 3 values, each in [0, 255]. The previous background is kept when the new one is invalid.

  • A unit test is covering the code added / modified by this PR
  • A mention of the change is present in CHANGELOG.md
  • This PR is ready to be merged

@andersonhc
andersonhc merged commit d3c1f49 into py-pdf:master Nov 3, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants