Mukesh Kumar
Mukesh Kumar

Reputation: 783

Parsing a PDF file using IText to add hyper link in existing texts

I know that PDFs are not for editing,but I have a requirement where I need to parse a PDF and modify it to convert all text elements to a hyper link. Is there a way to achieve this?

Many Thanks,

Upvotes: 0

Views: 789

Answers (1)

mkl
mkl

Reputation: 95918

To convert text elements to hyper links involves multiple operations:

  1. You have to apply text extraction with the twist of also extracting the text location, not merely the plain text.

  2. In that extracted text with locations you have to find all text parts which you want to make hyper links.

  3. Having found them, take their locations and add appropriate annotations to make them hyper linked.

Extraction of text with location can be done in iText implementing a variant of the LocationTextExtractionStrategy (cf. this answer; even though it is written for iTextSharp, the same principles apply) and in PDFBox overriding PDFTextStripper.writeString(String, List<TextPosition>).

Upvotes: 1

Related Questions