Some test text!

Replace content

Replacing text & images in PDFs in PHP

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

$doc = new PDFDoc($filename);
$replacer = new ContentReplacer();
$page = $doc->GetPage(1);

// replace an image on the page
$target_region = $page->GetMediaBox();
$img = Image::Create($doc->GetSDFDoc(), $imagename);
$replacer->AddImage($target_region, $img->GetSDFObj());

// replace a text placeholder
$replacer->AddString("NAME", "John Smith");

// replace text in a given region
$text = "hello world";
$replacer->AddText($target_region, "hello world");

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).

Get the answers you need: Support

Upcoming Webinar: Customer Experience and Retaining Control: Boosting Document Automation and Efficiency in Financial Services | Sept 15, 2022 at 11 am PT


The Platform


© 2022 PDFTron Systems Inc. All rights reserved.


Terms of Use