> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/editing-page-content/replace.md).

# Replacing text & images in PDFs in Android

Learn how to replace text or images in a PDF using pdftron.PDF.ContentReplacer. Find full code samples for searching and replacing text strings and images in existing PDFs. Perfect for updating busine

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

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
PDFDoc doc = new PDFDoc(filename);
ContentReplacer replacer = new ContentReplacer();
Page page = doc.getPage(1);

// replace an image on the page
Rect target_region = page.GetMediaBox();
Image img = Image.create(doc, imagename);
replacer.addImage(target_region, img.getSDFObj());

// replace a text placeholder
replacer.addString("NAME", "John Smith");

// replace text in a given region
String text = "hello world";
replacer.addText(target_region, text);
replacer.process(page);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
val doc = PDFDoc(filename)
val replacer = ContentReplacer()
val page = doc.getPage(1)

// replace an image on the page
val target_region = page.mediaBox
val img = Image.create(doc, imagename)
replacer.addImage(target_region, img.sdfObj)

// replace a text placeholder
replacer.addString("NAME", "John Smith")

// replace text in a given region
val text = "hello world"
replacer.addText(target_region, text)
replacer.process(page)
```

{% endcode %}
{% endtab %}
{% endtabs %}

[Replace PDF text or images](/android/get-started/samples.md#contentreplacer) 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).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/editing-page-content/replace.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
