Skip to content

Commit fb40684

Browse files
committed
polished kb
1 parent 80e8cd9 commit fb40684

File tree

5 files changed

+43
-44
lines changed

5 files changed

+43
-44
lines changed
36.3 KB
Loading
25.9 KB
Loading
Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Inserting Formatted HTML content in another RadFlowDocument
2+
title: Inserting Formatted HTML content in another RadFlowDocument using WordsProcessing
33
description: Learn how to insert formatted HTML text in specific locations within a RadFlowDocument and preserve the styling using Telerik WordsProcessing.
44
type: how-to
55
page_title: How to Insert HTML and Preserve the Styles in RadWordsProcessing Document
@@ -10,78 +10,75 @@ res_type: kb
1010
ticketid: 1698628
1111
---
1212

13+
<style>
14+
img[alt$="><"] {
15+
border: 1px solid lightgrey;
16+
}
17+
18+
</style>
19+
1320
## Environment
1421
| Version | Product | Author |
1522
| ---- | ---- | ---- |
1623
| 2025.3.806| RadWordsProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
1724

1825
## Description
1926

20-
I need to insert HTML content into specific locations within a RadFlowDocument created using Telerik WordsProcessing. Additionally, I want to apply specific styles to the inserted content, such as font family, size, and weight.
27+
Leanr how to insert HTML content into specific locations within a [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}) using Telerik [WordsProcessing]({%slug radwordsprocessing-overview%}).
2128

22-
This knowledge base article also answers the following questions:
23-
- How to merge HTML content into a specific paragraph in Telerik WordsProcessing?
24-
- How to style a RadFlowDocument content programmatically?
25-
- How to use RadWordsProcessing to insert documents into specific table cells?
29+
|Input Content|Output Content|
30+
|----|----|
31+
|![Input Content ><](images/input-flow-content.png) | ![Input Content ><](images/output-flow-content.png) |
2632

2733
## Solution
2834

29-
To insert HTML content into specific locations in a RadFlowDocument and apply styles, follow these steps:
35+
To insert HTML content into specific locations in a RadFlowDocument, follow these steps:
3036

31-
### Inserting HTML Content into a Specific Location
37+
1. Importing the HTML content: Use the [HtmlFormatProvider]({%slug radwordsprocessing-formats-and-conversion-html-htmlformatprovider%}) to import HTML content into a [RadFlowDocument]({%slug radwordsprocessing-model-radflowdocument%}).
3238

33-
Use the `HtmlFormatProvider` to import HTML content into a `RadFlowDocument`. Then, use the `RadFlowDocumentEditor` to insert the imported document into a specific location in your target document.
39+
1. Inserting HTML Content into a Specific Location: Use the [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) to insert the imported document (step 1) into a specific location in your target document.
3440

3541
Example:
3642

3743
```csharp
38-
RadFlowDocument originalDocument = new RadFlowDocument();
39-
DocxFormatProvider docxProvider = new DocxFormatProvider();
40-
originalDocument = docxProvider.Import(File.ReadAllBytes("original.docx"), TimeSpan.FromSeconds(10));
44+
RadFlowDocument originalDocument = new RadFlowDocument();
45+
DocxFormatProvider docxProvider = new DocxFormatProvider();
46+
originalDocument = docxProvider.Import(File.ReadAllBytes("original.docx"), TimeSpan.FromSeconds(10));
4147

42-
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
43-
RadFlowDocument htmlDocument = htmlProvider.Import(File.ReadAllText("content.html"), TimeSpan.FromSeconds(10));
48+
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
49+
RadFlowDocument htmlDocument = htmlProvider.Import(File.ReadAllText("content.html"), TimeSpan.FromSeconds(10));
50+
51+
// Get paragraphs from the imported document
52+
var importedParagraphs = htmlDocument.EnumerateChildrenOfType<Paragraph>().ToList();
4453

45-
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(originalDocument);
46-
var tableCells = originalDocument.EnumerateChildrenOfType<TableCell>().ToList();
47-
TableCell cell = tableCells[3] as TableCell;
54+
// Move editor to the start of the target paragraph
55+
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(originalDocument);
4856

49-
// Move editor to the start of the target paragraph
50-
editor.MoveToParagraphStart(cell.Blocks.First() as Paragraph);
57+
var tableCells = originalDocument.EnumerateChildrenOfType<TableCell>().ToList();
58+
TableCell cell = tableCells[3] as TableCell;
59+
editor.MoveToParagraphStart(cell.Blocks.First() as Paragraph);
5160

52-
// Insert the HTML document
53-
editor.InsertDocument(htmlDocument);
54-
55-
string outputFilePath = "output.docx";
56-
File.Delete(outputFilePath);
57-
using (Stream output = File.OpenWrite(outputFilePath))
58-
{
59-
docxProvider.Export(originalDocument, output, TimeSpan.FromSeconds(10));
60-
}
61-
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
62-
```
61+
editor.InsertDocument(htmlDocument);
6362

64-
### Applying Styles to Imported Content
63+
string outputFilePath = "output.docx";
64+
File.Delete(outputFilePath);
65+
using (Stream output = File.OpenWrite(outputFilePath))
66+
{
67+
docxProvider.Export(originalDocument, output, TimeSpan.FromSeconds(10));
68+
}
6569

66-
Apply styles to the entire imported document before merging it into the target document. Use the `ThemableFontFamily`, `FontSize`, and `FontWeight` properties.
70+
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
71+
```
6772

68-
Example:
6973

70-
```csharp
71-
htmlDocument.FontFamily = new ThemableFontFamily("Arial Narrow");
72-
htmlDocument.FontSize = UnitHelper.PointToDip(10);
73-
htmlDocument.FontWeight = FontWeights.Bold;
74-
```
7574

7675
### Additional Notes
7776

78-
- To target specific locations in the document, use the `RadFlowDocumentEditor` to navigate to the desired position.
77+
- To target specific locations in the document, use the [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%}) to navigate to the desired position.
7978
- Ensure the original document and imported HTML content are compatible in terms of styles and formatting.
8079

8180
## See Also
8281

83-
- [Insert Documents](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/editing/insert-documents)
84-
- [RadWordsProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/overview)
85-
- [HtmlFormatProvider API Reference](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/formats/html)
86-
- [RadFlowDocumentEditor API Reference](https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/editing/document-editor)
87-
---
82+
- [HtmlFormatProvider]({%slug radwordsprocessing-formats-and-conversion-html-htmlformatprovider%})
83+
- [Insert Documents]({%slug radwordsprocessing-editing-insert-documents%})
84+
- [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%})

libraries/radwordsprocessing/editing/insert-documents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ You could merge documents at a specific position using the InsertDocument() meth
9595
* [Clone and Merge]({%slug radwordsprocessing-editing-clone-and-merge%})
9696
* [Section]({%slug radwordsprocessing-model-section%})
9797
* [Paragraph]({%slug radwordsprocessing-model-paragraph%})
98+
* [Inserting Formatted HTML content in another RadFlowDocument using WordsProcessing]({%slug inserting-html-and-styling-radwordsprocessing%})

libraries/radwordsprocessing/editing/radflowdocumenteditor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,4 @@ The above method will delete everything between the "start" and "end" elements.
337337
* [RadFlowDocument API Reference](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.RadFlowDocument.html)
338338
* [Document model]({%slug radwordsprocessing-model%})
339339
* [Find and Replace]({%slug radwordsprocessing-editing-find-and-replace%})
340+
* [Inserting Formatted HTML content in another RadFlowDocument using WordsProcessing]({%slug inserting-html-and-styling-radwordsprocessing%})

0 commit comments

Comments
 (0)