# Replace Placeholder Text with Images in Telerik WordsProcessing

## Environment

| Version    | Product                                                                                                                         | Author                                                                |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| 2026.2.519 | [RadWordsProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview) | [Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov) |

## Description

I want to programmatically replace placeholders in a Word document, such as \[\*1], \[\*2], and so on, with images by using [RadWordsProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview). The [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) API can do this by replacing the placeholder text with an [ImageInline](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/imageinline).

This knowledge base article also answers the following questions:

* How to use Telerik WordsProcessing to replace text with an image.
* How to programmatically replace placeholders in a Word document with images.
* How to handle dynamic text-to-image replacement in Telerik WordsProcessing.

## Solution

To replace placeholders in a Word document with images using [RadWordsProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview), follow these steps:

1. Load the Word document with [DocxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/formats-and-conversion/word-file-formats/docx/docxformatprovider).
2. Create a [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) and prepare an [ImageInline](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/imageinline).
3. Use [ReplaceText()](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements) to swap the placeholder with the image.

Below is a sample implementation in C#:

```csharp
using System;
using System.IO;
using Telerik.Windows.Documents.Flow.FormatProviders.Docx;
using Telerik.Windows.Documents.Flow.Model;
using Telerik.Windows.Documents.Flow.Model.Editing;
using Telerik.Windows.Documents.Flow.Model.Shapes;
using Telerik.Windows.Documents.Media;

class Program
{
    static void Main()
    {
        RadFlowDocument flowDocument;
        DocxFormatProvider docxFormatProvider = new DocxFormatProvider();
        using (Stream input = File.OpenRead("TestDocument.docx"))
        {
            flowDocument = docxFormatProvider.Import(input, null);
        }

        RadFlowDocumentEditor editor = new RadFlowDocumentEditor(flowDocument);

        ReplacePlaceholderWithImage(editor, flowDocument, "text placeholder 1", "image.jpeg");
        ReplacePlaceholderWithImage(editor, flowDocument, "text placehodler 2", "image.jpeg");

        string outputPath = "output.docx";
        using (Stream output = File.OpenWrite(outputPath))
        {
            docxFormatProvider.Export(flowDocument, output, null);
        }

        Console.WriteLine("Document updated successfully.");
    }

    private static void ReplacePlaceholderWithImage(
        RadFlowDocumentEditor editor,
        RadFlowDocument document,
        string placeholderText,
        string imagePath)
    {
        ImageInline imageInline = new ImageInline(document);
        byte[] imageData = File.ReadAllBytes(imagePath);
        imageInline.Image.ImageSource = new ImageSource(imageData, "jpeg");
        imageInline.Image.Size = new System.Windows.Size(100, 100);

        editor.ReplaceText(placeholderText, imageInline, true, true);
    }
}
```

### Key Points

* Use the `ReplaceText()` method of [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) to locate and replace placeholders.
* The [ImageInline](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/imageinline) object handles embedding images into the document.
* Customize the `ImageInline.Image.Size` property to set the dimensions of the image.

## See Also

* [RadWordsProcessing Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview)
* [RadFlowDocument](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument)
* [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor)
* [ImageInline](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/imageinline)
* [Replace Text with Document Elements](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements)
