Highlight text in a PDF with Python

Katharsis picture Katharsis · Oct 27, 2016 · Viewed 13.2k times · Source

I'm working on custom search engine for my PDF data corpus.

I have a transformation layer which is able to dump PDF content to text (using Apache Tika and GROBID). I have finished search layers and the view which return search results listing.

Now, I'd like to add highlighting feature on original PDF for the lines, where search terms was appeared. Yes, I wanna modifiy PDF files if it is necessary.

Is there any way for highlight text inside in PDF file? Are PDFMiner or PyPDF2 or other Python library is able to do that?

... or can you recommand other, maybe external service for it?

Answer

spacevillain picture spacevillain · Nov 18, 2016

You can highlight text using PyPDF2.

In order to find the text's location, check out this answer.