This is a migrated thread and some comments may be shown as answers.

Import Html, Export Docx highlighting color

3 Answers 263 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Casablanca
Top achievements
Rank 1
Casablanca asked on 08 Sep 2016, 07:19 AM

Hello!

We try to import HTML Source Code, and export it to OpenXml.

The problem is, that the highlighting - color of the Runs (RunProperties) does not match with the HTML-highlighting-colors.

The HTML string is for example:

<p style="margin-top: 0px;margin-bottom: 0px;line-height: 1.15;"><span style="font-family: 'Verdana';font-size: 16px;background-color: #F79646;">Test</span><span style="font-family: 'Verdana';font-size: 16px;"></span></p>

The WordProcessing - Code:

HtmlFormatProvider cHtmlFormatProvider = new HtmlFormatProvider();
RadDocument cDocument = cHtmlFormatProvider.Import(sHtmlString);
 
DocxFormatProvider cDocxFormatProvider = new DocxFormatProvider();
using (var fileStream = new MemoryStream())
{
    cProvider.Export(cDocument, fileStream);
    using (WordprocessingDocument wp = WordprocessingDocument.Open(fileStream, true))
    {
         //Paragraphs and runs etc...
    }
}

 

But if i check the RunProperties of the Run (of the Paragraph), i see that the highlighting color is 'yellow' but it should be #F79646 (Orange).

There is no other possibility for us, we have to export it to HTML.

The Html Source Code was produced by RadRichTextBox.

Please help us.

Thank you.

 

3 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 12 Sep 2016, 03:53 PM
Hi Alexander,

In MS Word, the highlight color has a limited set of colors that could be used. You can check the attached screenshot that shows the palette.

When DocxFormatProvider exports highlight color that is not on this limited set of colors, it tries to export the nearest color it finds. This is the reason for the mismatch. Here is the list of the available colors: 
{Colors.Transparent, "none"},
{Colors.Black, "black"},
{Colors.Blue, "blue"},
{Colors.Cyan, "cyan"},
{Color.FromArgb(255, 0, 0, 128), "darkBlue"},
{Color.FromArgb(255, 0, 128, 128), "darkCyan"},
{Color.FromArgb(255, 128, 128, 128), "darkGray"},
{Color.FromArgb(255, 0, 128, 0), "darkGreen"},
{Color.FromArgb(255, 128, 0, 128), "darkMagenta"},
{Color.FromArgb(255, 128, 0, 0), "darkRed"},
{Color.FromArgb(255, 128, 128, 0), "darkYellow"},
{Color.FromArgb(255, 0, 255, 0), "green"},
{Color.FromArgb(255, 192, 192, 192), "lightGray"},
{Color.FromArgb(255, 255, 0, 255), "magenta"},
{Colors.Red, "red"},
{Colors.White, "white"},
{Colors.Yellow, "yellow"}

Hope this information is useful.

Regards,
Tanya
Telerik by Progress

0
Casablanca
Top achievements
Rank 1
answered on 20 Sep 2016, 06:24 AM

Hi!

Thank you for your reply.

In that case, we have a table with a cell-background and a Text (without highlighting) made in RadRichTextBox.

But the Telerik library does it set as a highlighting, which does not support all colors and so are the background colors of the text wrong.

I have the examples in the attachment, first the original of the RadRichTextBox and the converted one, that you can see it.

Html Code of the example (produced by RadRichTextBox):

<table style="border-left: 1px solid #000000;border-top: 1px solid #000000;border-right: 1px solid #000000;border-bottom: 1px solid #000000;border-collapse: collapse;table-layout: auto;width: 626px;"><tr><td style="border-left: 1px solid #000000;border-top: 1px solid #000000;border-right: 1px solid #000000;border-bottom: 1px solid #000000;padding: 0px 5px 0px 5px;background-color: #F79646;vertical-align: top;" align="left" valign="top"><p style="margin-top: 0px;margin-bottom: 0px;line-height: 1;text-align: center;"><span style="font-family: 'Verdana';font-size: 16px;color: #FFFFFF;"><b><i><u>Test - Header</u></i></b></span><span style="font-family: 'Verdana';font-size: 16px;"></span></p></td></tr><tr><td style="border-left: 1px solid #000000;border-top: 1px solid #000000;border-right: 1px solid #000000;border-bottom: 1px solid #000000;padding: 0px 5px 0px 5px;background-color: #FCD5B5;vertical-align: top;" align="left" valign="top"><p style="margin-top: 0px;margin-bottom: 0px;line-height: 1;text-align: center;"><span style="font-family: 'Verdana';font-size: 13.34px;">Test - Body</span><span style="font-family: 'Verdana';font-size: 16px;"></span></p></td></tr></table><p style="margin-top: 0px;margin-bottom: 12px;line-height: 1.15;"><span style="font-family: 'Verdana';font-size: 16px;"> </span></p>

Regards,

Casablanca Hotelsoftware

0
Accepted
Tanya
Telerik team
answered on 22 Sep 2016, 11:41 AM
Hi,

The run doesn't have any highlight color set, but it is inherited from its parent. Thus, the mismatch in the colors. In order to avoid this difference in the exported document, you could set the HighlightColor of the spans to Transparent either in the HTML document or after importing it to RadFlowDocument. The following snippet shows how you can set the highlight of all the Run elements in a RadFlowDocument instance:
IEnumerable<Run> runs = this.document.EnumerateChildrenOfType<Run>();
foreach (var run in runs)
{
    run.Properties.HighlightColor.LocalValue = Colors.Transparent;
}

I hope this is helpful.

Regards,
Tanya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
WordsProcessing
Asked by
Casablanca
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Casablanca
Top achievements
Rank 1
Share this question
or