New to Telerik Document ProcessingStart a free 30-day trial

Replace Placeholder Text with Images in Telerik WordsProcessing

Updated on Jun 17, 2026

Environment

VersionProductAuthor
2026.2.519RadWordsProcessingYoan Karamanov

Description

I want to programmatically replace placeholders in a Word document, such as [*1], [*2], and so on, with images by using RadWordsProcessing. The RadFlowDocumentEditor API can do this by replacing the placeholder text with an 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, follow these steps:

  1. Load the Word document with DocxFormatProvider.
  2. Create a RadFlowDocumentEditor and prepare an ImageInline.
  3. Use ReplaceText() 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 to locate and replace placeholders.
  • The ImageInline object handles embedding images into the document.
  • Customize the ImageInline.Image.Size property to set the dimensions of the image.

See Also