1

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

My favourite answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.