pypdf
pypdf copied to clipboard
Annotation lines too thin/non-existent
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
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:
Sorry how am I supposed to use that? I changed the value upwards of 500 and I still cannot see the shape.
do not forget to change also the color
Which variable does that? hopefully not interiour_color
as I am hoping for a black-bordered transparent rectangle.
try /C
.If not you can try some reverse engineering generating an annotation with acrobat reader
@bobweasel is it good ?
Where do I add /c
?
/C
is another field:
annotation[NameObject("/C")] = ArrayObject([FloatObject(1.0),FloatObject(0.0),FloatObject(0.0)])
Thanks that worked! Perhaps could add this to the rework? Would be happy to help.
Thanks that worked! Perhaps could add this to the rework? Would be happy to help.
there parameters are planned 😉
Let's leave it open for the moment. At the very least we could add this to the documentation :-)