'How to add text annotation to existing PDF using pdf-annotate Python
I'm trying to use this Python library called pdf-annotate to add text annotation to existing PDF files. Here's the documentation of the library: https://github.com/plangrid/pdf-annotate
I got this sample code that add a square on the bottom left corner of the pdf file but couldn't figure out how to add free text instead of square. For example, I want to add a comment like "This document has been reviewed." instead of the square. This should be annotation on the existing pdf page instead of adding a new page to the pdf.
from pdf_annotate import PdfAnnotator, Appearance, Location
annotator = PdfAnnotator('sample.pdf')
annotator.add_annotation(
'square',
Location(x1=50, y1=50, x2=100, y2=100, page=0),
Appearance(fill=(1, 0, 0))
)
annotator.write('annotated.pdf')
I've been trying to review the source code in the documentation to figure out how to add text instead of square but couldn't figure it out. Does anyone know how to use this library to add text?
Solution 1:[1]
In my case the following worked:
annotator.add_annotation(
'text',
Location(x1=x_start, y1=y_start, x2=x_end, y2=y_end, page=0),
Appearance(content='Review...', font_size=10, fill=(0,0,0)),
)
But especially the "fill" argument is required. It gives the color of the text and must be specefied.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jeezer |