RadRichTextBox RtfFormatProvider Style of type Paragraph can not have linked style of type Paragraph

0 Answers 115 Views
RichTextBox
Kamran
Top achievements
Rank 3
Iron
Iron
Veteran
Kamran asked on 22 Jun 2022, 06:08 PM | edited on 23 Jun 2022, 08:09 AM

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.

Tanya
Telerik team
commented on 24 Jun 2022, 07:22 AM

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.

Kamran
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 24 Jun 2022, 06:13 PM

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.

Tanya
Telerik team
commented on 29 Jun 2022, 11:40 AM

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);
// ...

This way, you can still use the API of WordsProcessing and RadFlowDocument.

I have also logged a report for the cause of the error you are getting. You can subscribe to the related public item if you would like to receive notifications about status changes on it: WordsProcessing: Styles inside HTML document exported from RadRichTextBox for WPF is not properly imported.

Hope this is helpful.

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Kamran
Top achievements
Rank 3
Iron
Iron
Veteran
Share this question
or