From e4782be72567977c2b10494db42aa9287921fa46 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Wed, 17 Jun 2026 10:35:54 +0000 Subject: [PATCH 1/2] Added new kb article replace-text-placeholder-with-image-telerik-wordsprocessing --- ...lder-with-image-telerik-wordsprocessing.md | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md diff --git a/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md b/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md new file mode 100644 index 00000000..1e2ba846 --- /dev/null +++ b/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md @@ -0,0 +1,104 @@ +--- +title: Replacing Word Placeholders with Images Using Telerik WordsProcessing +description: Learn how to use Telerik WordsProcessing to replace placeholders in a Word document with images programmatically. +type: how-to +page_title: Replace Placeholder Text with Images in Telerik WordsProcessing +meta_title: Replace Placeholder Text with Images in Telerik WordsProcessing +slug: replace-word-placeholder-with-image-telerik-wordsprocessing +tags: telerik, wordsprocessing, radflowdocumenteditor, replace-text, imageinline +res_type: kb +ticketid: 1715583 +--- + +## Environment + + + + + + + + + + + + +
Product +Telerik Document Processing WordsProcessing +
Version 2025.4.1216
+ +## Description + +I want to programmatically replace placeholders in a Word document, such as [*1], [*2], etc., with images using Telerik WordsProcessing. The images can be in formats like .jpg, .tiff, or .png, and I would like to use the `RadFlowDocumentEditor` for this purpose. + +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 Telerik WordsProcessing, follow these steps: + +1. Load the Word document using the `DocxFormatProvider`. +2. Use the `RadFlowDocumentEditor` to search for placeholder text. +3. Replace the placeholder text with an `ImageInline` element. + +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.Media; + +class Program +{ + static void Main() + { + // Load the Word document + RadFlowDocument flowDocument; + DocxFormatProvider docxFormatProvider = new DocxFormatProvider(); + using (Stream input = File.OpenRead("TestDocument.docx")) + { + flowDocument = docxFormatProvider.Import(input, null); + } + + // Initialize the document editor + RadFlowDocumentEditor editor = new RadFlowDocumentEditor(flowDocument); + + // Create an ImageInline object + ImageInline imageInline = new ImageInline(flowDocument); + byte[] imageData = File.ReadAllBytes("image.jpeg"); // Replace with your image file path + imageInline.Image.ImageSource = new ImageSource(imageData, "jpeg"); + imageInline.Image.Size = new System.Windows.Size(100, 100); // Set image dimensions + + // Replace placeholders with the image + editor.ReplaceText("[*1]", imageInline, true, true); // Replace [*1] + editor.ReplaceText("[*7]", imageInline, true, true); // Replace [*7] + + // Save the modified document + string outputPath = "output.docx"; + using (Stream output = File.OpenWrite(outputPath)) + { + docxFormatProvider.Export(flowDocument, output, null); + } + + Console.WriteLine("Document updated successfully."); + } +} +``` + +### 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 + +- [WordsProcessing Documentation](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview) +- [RadFlowDocument Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument) +- [RadFlowDocumentEditor Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) +- [Replace Text with Document Elements](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements) From e0fdb234cb89bb95b034372e4532745b8f84e3da Mon Sep 17 00:00:00 2001 From: "PROGRESS\\ykaraman" Date: Wed, 17 Jun 2026 13:50:27 +0300 Subject: [PATCH 2/2] KB - Word - Replace Text with Image --- ...lder-with-image-telerik-wordsprocessing.md | 92 +++++++++---------- .../replace-document-elements.md | 1 + 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md b/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md index 1e2ba846..dfcbec54 100644 --- a/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md +++ b/knowledge-base/replace-text-placeholder-with-image-telerik-wordsprocessing.md @@ -1,35 +1,24 @@ ---- -title: Replacing Word Placeholders with Images Using Telerik WordsProcessing -description: Learn how to use Telerik WordsProcessing to replace placeholders in a Word document with images programmatically. -type: how-to -page_title: Replace Placeholder Text with Images in Telerik WordsProcessing -meta_title: Replace Placeholder Text with Images in Telerik WordsProcessing -slug: replace-word-placeholder-with-image-telerik-wordsprocessing -tags: telerik, wordsprocessing, radflowdocumenteditor, replace-text, imageinline -res_type: kb -ticketid: 1715583 +--- +title: Replace Placeholder Text with Images in Telerik WordsProcessing +description: Learn how to replace placeholder text in a Word document with images by using RadWordsProcessing. +type: how-to +page_title: Replace Placeholder Text with Images in Telerik WordsProcessing +meta_title: Replace Placeholder Text with Images in Telerik WordsProcessing +slug: replace-text-placeholder-with-image-telerik-wordsprocessing +tags: radwordsprocessing, wordsprocessing, placeholder, replace, image, editor, docx, telerik, word +res_type: kb +ticketid: 1715583 --- ## Environment - - - - - - - - - - - -
Product -Telerik Document Processing WordsProcessing -
Version 2025.4.1216
+| Version | Product | Author | +| --- | --- | --- | +| 2026.2.519 | [RadWordsProcessing]({%slug 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], etc., with images using Telerik WordsProcessing. The images can be in formats like .jpg, .tiff, or .png, and I would like to use the `RadFlowDocumentEditor` for this purpose. +I want to programmatically replace placeholders in a Word document, such as [*1], [*2], and so on, with images by using [RadWordsProcessing]({%slug radwordsprocessing-overview%}). The [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) API can do this by replacing the placeholder text with an [ImageInline]({%slug radwordsprocessing-model-imageinline%}). This knowledge base article also answers the following questions: - How to use Telerik WordsProcessing to replace text with an image. @@ -38,11 +27,11 @@ This knowledge base article also answers the following questions: ## Solution -To replace placeholders in a Word document with images using Telerik WordsProcessing, follow these steps: +To replace placeholders in a Word document with images using [RadWordsProcessing]({%slug radwordsprocessing-overview%}), follow these steps: -1. Load the Word document using the `DocxFormatProvider`. -2. Use the `RadFlowDocumentEditor` to search for placeholder text. -3. Replace the placeholder text with an `ImageInline` element. +1. Load the Word document with [DocxFormatProvider]({%slug radwordsprocessing-formats-and-conversion-docx-docxformatprovider%}). +2. Create a [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) and prepare an [ImageInline]({%slug radwordsprocessing-model-imageinline%}). +3. Use [ReplaceText()]({%slug radwordsprocessing-editing-replace-document-elements%}) to swap the placeholder with the image. Below is a sample implementation in C#: @@ -52,13 +41,13 @@ 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() { - // Load the Word document RadFlowDocument flowDocument; DocxFormatProvider docxFormatProvider = new DocxFormatProvider(); using (Stream input = File.OpenRead("TestDocument.docx")) @@ -66,20 +55,11 @@ class Program flowDocument = docxFormatProvider.Import(input, null); } - // Initialize the document editor RadFlowDocumentEditor editor = new RadFlowDocumentEditor(flowDocument); - // Create an ImageInline object - ImageInline imageInline = new ImageInline(flowDocument); - byte[] imageData = File.ReadAllBytes("image.jpeg"); // Replace with your image file path - imageInline.Image.ImageSource = new ImageSource(imageData, "jpeg"); - imageInline.Image.Size = new System.Windows.Size(100, 100); // Set image dimensions - - // Replace placeholders with the image - editor.ReplaceText("[*1]", imageInline, true, true); // Replace [*1] - editor.ReplaceText("[*7]", imageInline, true, true); // Replace [*7] + ReplacePlaceholderWithImage(editor, flowDocument, "text placeholder 1", "image.jpeg"); + ReplacePlaceholderWithImage(editor, flowDocument, "text placehodler 2", "image.jpeg"); - // Save the modified document string outputPath = "output.docx"; using (Stream output = File.OpenWrite(outputPath)) { @@ -88,17 +68,33 @@ class Program 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. + +* Use the `ReplaceText()` method of [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) to locate and replace placeholders. +* The [ImageInline]({%slug 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 -- [WordsProcessing Documentation](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview) -- [RadFlowDocument Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument) -- [RadFlowDocumentEditor Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) -- [Replace Text with Document Elements](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements) +* [RadWordsProcessing Overview]({%slug radwordsprocessing-overview%}) +* [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}) +* [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) +* [ImageInline]({%slug radwordsprocessing-model-imageinline%}) +* [Replace Text with Document Elements]({%slug radwordsprocessing-editing-replace-document-elements%}) diff --git a/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements.md b/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements.md index ebe4c7f7..30bf2d5e 100644 --- a/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements.md +++ b/libraries/radwordsprocessing/editing/find-and-replace/replace-document-elements.md @@ -54,3 +54,4 @@ You can search and replace text using [RadFlowDocumentEditor]({%slug radwordspro * [Find and Replace Text and Style]({%slug radwordsprocessing-editing-find-and-replace%}) * [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) * [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}) +* [Replace Placeholder Text with Images in Telerik WordsProcessing]({%slug replace-text-placeholder-with-image-telerik-wordsprocessing%})