Replacing text & images in PDFs with Android

To find text or images and replace it in a PDF.

1PDFDoc doc = new PDFDoc(filename);
2ContentReplacer replacer = new ContentReplacer();
3Page page = doc.getPage(1);
4
5// replace an image on the page
6Rect target_region = page.GetMediaBox();
7Image img = Image.create(doc, imagename);
8replacer.addImage(target_region, img.getSDFObj());
9
10// replace a text placeholder
11replacer.addString("NAME", "John Smith");
12
13// replace text in a given region
14String text = "hello world";
15replacer.addText(target_region, text);
16replacer.process(page);

Replace PDF text or images
Full code sample which shows how to use pdftron.PDF.ContentReplacer to search and replace text strings and images in existing PDF (e.g. business cards and other PDF templates).

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales