Skip to content

ENH: Allow setting border color for rectangle annotations - #4297

Merged
stefan6419846 merged 4 commits into
py-pdf:mainfrom
Ak4shh:fix/rectangle-border-color
Oct 31, 2026
Merged

stefan6419846 merged 4 commits into
py-pdf:mainfrom
Ak4shh:fix/rectangle-border-color

Conversation

@Ak4shh

@Ak4shh Ak4shh commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1649.

Rectangle annotations omitted /C, which viewers can interpret as a transparent border. Rectangle now defaults to a black border and accepts a keyword-only border_color parameter. Passing None preserves the previous behavior of omitting /C. Interior color remains independently configurable.

Added tests for the default border and PDF round trips with black, red, and omitted border colors. Updated the annotation guide, including the spelling of interior_color.

Validation: 41 annotation tests passed; Ruff and focused mypy passed. PyMuPDF rendering confirmed visible borders for black and red and no border when the color is omitted. Acrobat and browser viewers were not checked.

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.65%. Comparing base (9808f6b) to head (08552c3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4297   +/-   ##
=======================================
  Coverage   98.65%   98.65%           
=======================================
  Files          59       59           
  Lines       11962    11964    +2     
  Branches     2270     2271    +1     
=======================================
+ Hits        11801    11803    +2     
  Misses         84       84           
  Partials       77       77           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PJBrs

PJBrs commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Would it be useful to have the new Color class in this PR? See here:

https://github.com/py-pdf/pypdf/blob/main/pypdf/generic/_color.py

@stefan6419846 stefan6419846 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree that we should use a black border by default. Instead, we should provide a way for the user to pass a border color and default it to the old behavior (to retain backwards-compatibility).

@stefan6419846

Copy link
Copy Markdown
Collaborator

Would it be useful to have the new Color class in this PR?

This would require us to refine the public API for the Color class in a way that only the relevant functionality is exposed publicly and each change would require a deprecation process.

Does the class really have any benefits over passing hex-based strings here?

`border_color` now defaults to None, preserving the previous output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ak4shh <akashposa40@gmail.com>
@Ak4shh

Ak4shh commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Done. border_color now defaults to None, so /C is omitted as before.

Comment thread tests/test_annotations.py Resolved
Comment thread tests/test_annotations.py Resolved
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
@stefan6419846 stefan6419846 changed the title BUG: Add a default border color to rectangle annotations ENH: Allow setting border color for rectangle annotations Oct 31, 2026
@stefan6419846
stefan6419846 merged commit 140204c into py-pdf:main Oct 31, 2026
21 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.

AnnotationBuilder.rectangle() does not create a bordered rectangle

3 participants