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

Importing HTML using HtmlFormatProvider changes formatting

5 Answers 351 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Vic
Top achievements
Rank 2
Vic asked on 21 Feb 2014, 07:54 PM
Hi,

I'm using version 2013.3.1316.1050, the previous versions did not have this issue.

When I import simple html it now increases the line height and I can't figure out how to shorten it..

var htmlProvider = new HtmlFormatProvider();
RadDocument document = htmlProvider.Import(html);
RichText.InsertFragment(new DocumentFragment(document));

Test HTML: "<ul><li>Test1</li><li>Test2</li><li>Test3<ul><li>Test 4</li></ul></li></ul>"

After I call InsertFragment I tried:

document.LineSpacingType = LineSpacingType.Auto;
document.LineSpacing = .75;
document.ParagraphDefaultSpacingBefore = _.25;
document.ParagraphDefaultSpacingAfter = .25;

Is there anyway to control this?

If I use binding to the same HTML its fine, just when calling Import.

Any help is appreciated, thanks,
Vic

5 Answers, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 24 Feb 2014, 12:45 PM
Hello Vic,

 Thank you for contacting us about this issue.

It is related to the automatic spacing. I will explain in few words how the automatic spacing works.

The automatic spacing is implemented to match the spacing which will be applied to the paragraph in an HTML document where no explicit spacing before or after is specified. The AutomaticSpacingAfeter and AutomaticSpacingBefore are properties of the paragraph and are set to true in the default style "Normal Web", which is the default style when importing HTML document.

The problem you have observed is a bug in the implementation of automatic spacing after related to lists. I will log this issue to our to do list for investigation and fix.

Meanwhile as workaround you can set the desired spacing to the default paragraph style when importing from HTML, the "Normal Web". Here is example on how to do it:
this.radRichTextBox.Document.StyleRepository["NormalWeb"].ParagraphProperties.SpacingAfter = 0;
this.radRichTextBox.Document.StyleRepository["NormalWeb"].ParagraphProperties.AutomaticSpacingAfter = false;

Please notice that this will affect all paragraphs with this style applied. 
You could apply it only to the paragraphs in list. Here is how you could do it:
foreach (Paragraph paragraph in this.radRichTextBox.Document.EnumerateChildrenOfType<Paragraph>())
{
    if (paragraph.IsInList)
    {
        paragraph.AutomaticSpacingAfter = false;
        paragraph.SpacingAfter = 0;
    }
}

In appreciation for your involvement I have updated your Telerik points. If you have further questions please do not hesitate to contact us again.

Regards,
Mihail
Telerik
0
Vic
Top achievements
Rank 2
answered on 24 Feb 2014, 10:11 PM
Hi Mihail,

Thanks for your reply, tweaked your fix for my needs and is now working!

Thanks for the points :)

Regards,
Vic
0
bhargava
Top achievements
Rank 1
answered on 18 Jun 2015, 04:56 PM

hi,

I am using RadRichTextBox  which has the document property is set to HtmlFormartProvider. I don't have any problem with spacing when loading but, when I want to increase the spacing between two items (td's)  vertically , I can't control the space .It takes quite a lot of empty space.I don't have this problem with horizontal spacing.

 

              HtmlFormatProvider prdf = new HtmlFormatProvider();
                 var document = prdf.Import(result);
                    this.RichTextBox.Document = document;

 

this is how my o/p looks:

 

1.name 

2.dob

3.age

4.height

I want to increase the height b/w age and height after loading using the mouse as I am using HtmlFormartProvider , I have a table like structure .So, when I hover over the age I get a up and down arrow to adjust the height. But, I can't control the height .

 

Any suggestions.

 

Thanks,

Bhargava 

0
bhargava
Top achievements
Rank 1
answered on 22 Jun 2015, 01:17 PM

Hi Mihail,

​Can you please suggest a solution..

0
Petya
Telerik team
answered on 23 Jun 2015, 01:47 PM
Hi Bhargava,

Could you send over some images of the visual result you get and the source HTML you are passing to the control. I'm having a hard time understanding what exactly you are trying to achieve. You mentioned tables and td elements, but the example you gave looks like a list and I am not sure I entirely understand your scenario.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Vic
Top achievements
Rank 2
Answers by
Mihail
Telerik team
Vic
Top achievements
Rank 2
bhargava
Top achievements
Rank 1
Petya
Telerik team
Share this question
or