# Inserting Formatted HTML content in another RadFlowDocument using WordsProcessing

<style>
img[alt$="><"] {
  border: 1px solid lightgrey;
}

</style>

## Environment

| Version    | Product            | Author                                                                          |
| ---------- | ------------------ | ------------------------------------------------------------------------------- |
| 2025.3.806 | RadWordsProcessing | [Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova) |

## Description

Learn how to insert HTML content at specific locations within a `RadFlowDocument` using Telerik [WordsProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview).

| Input Content                                                                                                                                           | Output Content                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![Input Content ><](https://www.telerik.com/document-processing-libraries/documentation/assets/be3ba1f7faf97a42a69c9f62e3f8695a/input-flow-content.png) | ![Input Content ><](https://www.telerik.com/document-processing-libraries/documentation/assets/98ff91e2278ef423b294dd4a1fe081e4/output-flow-content.png) |

## Solution

To insert HTML content at specific locations in a `RadFlowDocument`, follow these steps:

1. Use the [HtmlFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/formats-and-conversion/html/htmlformatprovider) to import HTML content into a [RadFlowDocument](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument).

2. Use the [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) to insert the imported document (step 1) into a specific location in your target document.

**Example 1: Insert HTML Content into a Specific Table Cell**

```csharp
            RadFlowDocument originalDocument = new RadFlowDocument();
            DocxFormatProvider docxProvider = new DocxFormatProvider();
            originalDocument = docxProvider.Import(File.ReadAllBytes("original.docx"), TimeSpan.FromSeconds(10));

            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadFlowDocument htmlDocument = htmlProvider.Import(File.ReadAllText("content.html"), TimeSpan.FromSeconds(10));
             
            // Get paragraphs from the imported document
            var importedParagraphs = htmlDocument.EnumerateChildrenOfType<Paragraph>().ToList();

            // Move editor to the start of the target paragraph
            RadFlowDocumentEditor editor = new RadFlowDocumentEditor(originalDocument);

            var tableCells = originalDocument.EnumerateChildrenOfType<TableCell>().ToList();
            TableCell cell = tableCells[3] as TableCell;
            editor.MoveToParagraphStart(cell.Blocks.First() as Paragraph);

            editor.InsertDocument(htmlDocument); 

            string outputFilePath = "output.docx";
            File.Delete(outputFilePath);
            using (Stream output = File.OpenWrite(outputFilePath))
            {
                docxProvider.Export(originalDocument, output, TimeSpan.FromSeconds(10));
            }

            Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
```

### Additional Notes

* To target specific locations in the document, use the [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) to navigate to the desired position.
* Verify that the original document and imported HTML content are compatible in terms of styles and formatting.

## See Also

* [HtmlFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/formats-and-conversion/html/htmlformatprovider)
* [Insert Documents](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/insert-documents)
* [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor)
