1

I need to find some text in a pdf document and put an image there, such as: "My car" in a document and place the image below / next to that text.

{.....
BufferedImage image = resizeImage(base64Picture, pictureScaling);
PDDocument document = PDDocument.load(base64Pdf);
int lastPage = document.getNumberOfPages()-1;
PDPage page = document.getPage(lastPage);  
PDImageXObject pdImage = LosslessFactory.createFromImage(doc, image);
PDPageContentStream contents = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND, false);

// find location of "My car"

contents.drawImage(); // draw image below / next to "My car"

.....}
user7327905
  • 15
  • 1
  • 5
  • 1
    For PdfBox you find multiple questions and answers on the topic of extracting text with coordinates, e.g. [here](https://stackoverflow.com/a/50514745/1729265), [here](https://stackoverflow.com/q/46080131/1729265), or [here](https://stackoverflow.com/a/33027322/1729265). You merely need to follow these examples and look for "My car" in the analyzed text with coordinates. – mkl Aug 30 '19 at 08:53
  • If it is a one time only thing, then use PDFDebugger to see the coordinates (move the mouse). – Tilman Hausherr Aug 30 '19 at 08:54
  • Thanks for advice...@Tilman Hausherr, the document should be dynamic – user7327905 Aug 30 '19 at 09:05

0 Answers0