pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

AnnotationBuilder.rectangle() does not create a bordered rectangle

Open musman920 opened this issue 1 year ago • 2 comments

When trying to create a rectangle on pdf, there is no box displayed. If the argument interiour_color is passed, then the rectangle is displayed. How to create just a bordered rectangle as displayed in https://pypdf.readthedocs.io/en/stable/user/adding-pdf-annotations.html#rectangle

Environment

Code + PDF

This is a minimal, complete example that shows the issue:

annotation = AnnotationBuilder.rectangle(
                # array of four integers [xLL, yLL, xUR, yUR] specifying the clickable rectangular area
                # add LowerLeft to UpperRight to maintain width and height
                rect=(42, 42, (510 + 42), (340 + 42)),
                # interiour_color="#bcceeb",
            )

samplerectangle.pdf

musman920 avatar Feb 21 '23 08:02 musman920

I did the test and the color not being present seems to be interpreted as transparent at least in Acrobat Reader and PDF.js I can see it if I add : annotation[pypdf.generic.NameObject("/C")] = pypdf.generic.ArrayObject([pypdf.generic.FloatObject(1.0),pypdf.generic.FloatObject(0.0),pypdf.generic.FloatObject(0.0)])

@MartinThoma can you confirm the behavior. Shouldn't it be a good idea to add params to pass the border color and/or a variable to set the default color?

pubpub-zz avatar Feb 23 '23 22:02 pubpub-zz

add params to pass the border color

We can do that :+1:

I think for all annotations we should make all new arguments keyword-only. It's very likely that we will add quite a bunch of parameters and I don't want to have (a) a very inconsistent order or (b) do weird hacks around ordering.

MartinThoma avatar Feb 24 '23 19:02 MartinThoma