I am converting HTML document to RTF by Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider.
Conversion works fine, but When I am binding final RTF document to RadRichTextBox editor (RtfFormatProvider), It gives me following error
Style of type Paragraph can not have linked style of type Paragraph.
System.InvalidOperationException: Style of type Paragraph can not have linked style of type Paragraph. at Telerik.Windows.Documents.Model.Styles.StyleDefinition.CheckIsValidLinkedStyle(StyleDefinition linkedStyle) at Telerik.Windows.Documents.Model.Styles.StyleDefinition.set_LinkedStyle(StyleDefinition value) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStylesTable.InitializeRelatedStyles() at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStylesTable.ReadTable(RtfGroup group, RtfImportContext context) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfHandlers.RtfGroupHandlers.StylesTableHandler(RtfGroup group, RtfImportContext context) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfDocumentImporter.DoVisitGroup(RtfGroup group) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitElement(RtfElement element, Boolean recursive) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitGroupChildren(RtfGroup group, Boolean recursive) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfDocumentImporter.ImportRoot(RtfGroup rtfGroup) at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfDocumentImporter.Import(Stream input, RtfImportSettings settings) at Telerik.Windows.Documents.FormatProviders.Rtf.RtfFormatProvider.Import(Stream input) at Telerik.Windows.Documents.FormatProviders.Rtf.RtfFormatProvider.Import(String input)
For reference I am attaching sample project and html document.
We are facing lot of issue by such conversion. Sample Html document I shared is generated by Telerik Richtext box editor, but same document conversion is not working.
Hi Kamran,
You can directly use the format providers of RadRichTextBox - Telerik.Windows.Documents.FormatProviders.Rtf.RtfFormatProvider and Telerik.Windows.Documents.FormatProviders.Html. The other ones (containing Flow in their name) are classes related to the WordsProcessing library. I am attaching a modified version of the code that uses the API of RadRichTextBox.
Hope this is helpful.
Thanks Tanya,
The ServiceHelper.cs file I attached is extracted from Web API's class library, where I cannot use wpf RadRichTextBox libraries.
Is there any option to use Telerik.Windows.Documents.FormatProviders in .Net core web services.
Hi Kamran,
The API of RadRichTextBox can be used in WPF applications only. .NET Core is also supported by the control but still requires the Windows Compatibility Pack.
Another option I could suggest is to remove the style that causes the issue:
// ... document = htmlProvider.Import(content); foreach (var style in document.StyleRepository.Styles) { if (style.Name.Contains("Char")) { document.StyleRepository.Remove(style.Id); } } return rtfProvider.Export(document); // ...