pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

Annotation lines too thin/non-existent

Open bobweasel opened this issue 1 year ago • 12 comments

The annotation lines are very thin. I can only see them if i put a shape fill, but that means I get a filled-in shape as well. If I draw an annotation using Adobe Acrobat, I will be able to see the lines.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Windows-10-10.0.19044-SP0

$ python -c "import pypdf;print(pypdf.__version__)"
3.10.0

Code + PDF

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

from pypdf import PdfReader, PdfWriter
from pypdf.generic import AnnotationBuilder

reader = PdfReader("1.pdf")
writer = PdfWriter()

page = reader.pages[0]
fields = reader.get_fields()

writer.append(reader)

annotation = AnnotationBuilder.rectangle(
    rect=(225, 469, 243, 484), interiour_color='000000'
)
writer.add_annotation(page_number=0, annotation=annotation)
annotation = AnnotationBuilder.rectangle(
    rect=(125, 469, 243, 484),
)
writer.add_annotation(page_number=0, annotation=annotation)

# write "output" to pypdf-output.pdf
with open("filled-out.pdf", "wb") as output_stream:
    writer.write(output_stream)

Share here the PDF file(s) that cause the issue. The smaller they are, the better. Let us know if we may add them to our tests! Any PDF file.

Traceback

This is the complete Traceback I see: No Traceback

bobweasel avatar Jun 21 '23 13:06 bobweasel

Annotation API is planned for rework (cf #1741) Meanwhile after having created the annotation you can complete its properties. For the rectangle width you have to adjust the border property:

from pypdf.generic import *
(...)
annotation = AnnotationBuilder.rectangle(
    rect=(225, 469, 243, 484), interiour_color='000000'
)
annotation[NameObject("/Border")] = ArrayObject([FloatObject(0),FloatObject(0),FloatObject(5.0)])

see pdf spec for more details: image

pubpub-zz avatar Jun 21 '23 17:06 pubpub-zz

Sorry how am I supposed to use that? I changed the value upwards of 500 and I still cannot see the shape.

bobweasel avatar Jun 21 '23 17:06 bobweasel

do not forget to change also the color

pubpub-zz avatar Jun 21 '23 17:06 pubpub-zz

Which variable does that? hopefully not interiour_color as I am hoping for a black-bordered transparent rectangle.

bobweasel avatar Jun 21 '23 18:06 bobweasel

try /C.If not you can try some reverse engineering generating an annotation with acrobat reader

pubpub-zz avatar Jun 21 '23 19:06 pubpub-zz

@bobweasel is it good ?

pubpub-zz avatar Jun 23 '23 18:06 pubpub-zz

Where do I add /c?

bobweasel avatar Jun 25 '23 18:06 bobweasel

/C is another field: annotation[NameObject("/C")] = ArrayObject([FloatObject(1.0),FloatObject(0.0),FloatObject(0.0)])

image

pubpub-zz avatar Jun 25 '23 18:06 pubpub-zz

Thanks that worked! Perhaps could add this to the rework? Would be happy to help.

bobweasel avatar Jun 26 '23 15:06 bobweasel

Thanks that worked! Perhaps could add this to the rework? Would be happy to help.

bobweasel avatar Jun 27 '23 16:06 bobweasel

there parameters are planned 😉

pubpub-zz avatar Jun 27 '23 21:06 pubpub-zz

Let's leave it open for the moment. At the very least we could add this to the documentation :-)

MartinThoma avatar Jun 30 '23 17:06 MartinThoma