Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation lines too thin/non-existent #1904

Open
bobweasel opened this issue Jun 21, 2023 · 12 comments
Open

Annotation lines too thin/non-existent #1904

bobweasel opened this issue Jun 21, 2023 · 12 comments
Labels
Easy This issue is a good starting point for first-time contributors nf-documentation Non-functional change: Documentation

Comments

@bobweasel
Copy link

bobweasel commented Jun 21, 2023

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

@pubpub-zz
Copy link
Collaborator

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

@bobweasel
Copy link
Author

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

@pubpub-zz
Copy link
Collaborator

do not forget to change also the color

@bobweasel
Copy link
Author

bobweasel commented Jun 21, 2023

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

@pubpub-zz
Copy link
Collaborator

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

@pubpub-zz
Copy link
Collaborator

@bobweasel
is it good ?

@bobweasel
Copy link
Author

Where do I add /c?

@pubpub-zz
Copy link
Collaborator

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

image

@bobweasel
Copy link
Author

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

1 similar comment
@bobweasel
Copy link
Author

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

@pubpub-zz
Copy link
Collaborator

there parameters are planned 😉

@MartinThoma
Copy link
Member

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

@MartinThoma MartinThoma reopened this Jun 30, 2023
@MartinThoma MartinThoma added nf-documentation Non-functional change: Documentation Easy This issue is a good starting point for first-time contributors labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy This issue is a good starting point for first-time contributors nf-documentation Non-functional change: Documentation
Projects
None yet
Development

No branches or pull requests

3 participants