Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highlight text using pdfbox when it's location in the pdf is known

Tags:

java

pdf

pdfbox

Does pdfbox provide some utility to highlight the text when I have it's co-ordinates?

Bounds of the text is known.

I know there are other libraries that provide the same functionality like pdfclown etc. But does pdfbox provide something like that?

like image 262
Alvin Avatar asked Aug 27 '13 10:08

Alvin


1 Answers

well i found this out. it is simple.

PDDocument doc = PDDocument.load(/*path to the file*/);
PDPage page = (PDPage)doc.getDocumentCatalog.getAllPages.get(i);
List annots = page.getAnnotations;
PDAnnotationTextMarkup markup = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.Su....);
markup.setRectangle(/*your PDRectangle*/);
markup.setQuads(/*float array of size eight with all the vertices of the PDRectangle in anticlockwise order*/);
annots.add(markup);
doc.save(/*path to the output file*/);
like image 169
Alvin Avatar answered Nov 05 '22 10:11

Alvin