Skip to content

set_margins: raise a clear error for a negative margin - #2094

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:negative-margins
Nov 2, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:negative-margins

Conversation

@RavSinghChandan

Copy link
Copy Markdown

set_margins(), set_left_margin(), set_top_margin() and set_right_margin() accepted a negative margin, so text was written past the edge of the page. They now raise ValueError: Left margin must be zero or a positive number (or Top / Right), like set_auto_page_break() does for the bottom margin since #2084.

set_margins() checks all its margins before changing any, so an invalid one leaves the others unchanged. Its default right=-1 (same as the left margin) still works.

  • 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 b2ceac7 into py-pdf:master Nov 2, 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