How to insert annotation into PDF using Python

I want to add text or annotation to an exsting pdf file in order to interpret some keywords.

At first I tried pyPdf and reportlib to combine the original pdf file and the new generated PDF interpretation file, but it does not work. Since the source file does not contain all pdf interpretation words and makes the new PDF file invisible. Do not know why? If I test merging two new PDF files with conversion to one, it works well.

So, I'm trying to use a different way to insert only annotations into an existing PDF file using python. Anyone have any related experience can give me a suggestion? Thanks!

+4
source share
1 answer

Adding a watermark to an existing pdf using PyPDF certainly works for me:

template = PdfFileReader(file("template.pdf", "rb")) #template pdf output=PdfFileWriter() #writer for the merged pdf for i in range(new.getNumPages()): page=template.getPage(i) page.mergePage(new.getPage(i)) output.addPage(page) 

Read my other SO answer for reference.

Read my full article to learn more about creating and merging PDF files in python.

0
source

All Articles