Replacing text & images in PDFs on Server/Desktop

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