0

How to get llx,lly,urx,ury position of word in a pdf using itext. Here requirement is that in a pdf need to add a digital signature above the word. this word is not a fixed position and this word may be comes in first page or 2nd page or in a same page in different positions. if I know the position of word then i can able to adjust the position making digital signature using sap.setVisibleSignature(new Rectangle(425, 218, 575, 248), 1, null); . final conclusion is here i should not use fixed positions of llx,lly, urx,ury for Rectangle class. Kindly advise how to find the word coordinators using itext.

Raj
  • 677
  • 3
  • 8
  • 16
  • Have you tried to implement the pseudo-code approach described in [this answer](https://stackoverflow.com/a/13719947/1729265)? – mkl Jul 08 '18 at 11:43

1 Answers1

2

Have a look at RegexBasedLocationExtractionStrategyin iText 7.

This class enables you to look for a given regular expression, and returns a collection of locations (page, x and y coordinate) that match.

Setup is relatively easy:

PdfDocument pdfDocument = new PdfDocument(new PdfReader(inputfile));

RegexBasedLocationExtractionStrategy strategy = new RegexBasedLocationExtractionStrategy("word_to_look_for");
PdfCanvasProcessor proc = new PdfCanvasProcessor(strategy);
proc.processPageContent(pdfDocument.getPage(1));

strategy.getResultantLocations(); // do something with the results
Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54
  • Dumb question, because this actually worked, but how would i be able to view these coordinates on my console? (console.writelin()) –  Aug 29 '19 at 18:09