Replacing text & images in PDFs on Server/Desktop

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

1$doc = new PDFDoc($filename);
2$replacer = new ContentReplacer();
3$page = $doc->GetPage(1);
4
5// replace an image on the page
6$target_region = $page->GetMediaBox();
7$img = Image::Create($doc->GetSDFDoc(), $imagename);
8$replacer->AddImage($target_region, $img->GetSDFObj());
9
10// replace a text placeholder
11$replacer->AddString("NAME", "John Smith");
12
13// replace text in a given region
14$text = "hello world";
15$replacer->AddText($target_region, "hello world");
16$replacer->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