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

Line Spacing

2 Answers 882 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 21 Feb 2017, 05:46 PM
Is there a clean way to set the line spacing for all text in a document (add both via import and user typed)?

I found the RichTextEditor.Document.LineSpacing property, but this appear to set an absolute of the spacing between the bottom of each instead the of space between each line, which would have to be based on font size.

I assume I could use this property and go through line by line looking at the font size and setting it when anything changed on the document, but that sounds like it would result in an excessive amount of overhead.

I'm not looking to use any special spacing or anything like that, just enforce single line spacing on the document regardless of font size and apply to to both imported text and user typed text.

Any help would be appreciated.

2 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 21 Feb 2017, 06:23 PM

I've done a little more digging.
The line spacing appears to be working as expected for user typed text.

However for imported text it imports with the multiple lines written on top of each other.

I am importing html using the HtmlProvider because I need to be able to pull in any formatting and images as well.

The imported html is generated by another RadRichTextEditor using the HtmlProvider to Export it to html string. (This all works when leave the line spacing to default or Auto but need to be able to enforce line spacing on the whole document and allow importing).

0
Hristo
Telerik team
answered on 22 Feb 2017, 08:08 AM
Hi Matt,

Thank you for writing.

It appears that the observed behavior is caused by the styles already defined in the document you are importing. You can achieve the desired result by performing a selection of the entire content and changing the paragraph line spacing properties.

Please check my code snippet below: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        this.radRichTextEditor1.Document = this.ImportHtml();
 
        this.radRichTextEditor1.Document.Selection.SelectAll();
        this.radRichTextEditor1.ChangeParagraphLineSpacing(1, LineSpacingType.AtLeast);
        this.radRichTextEditor1.ChangeParagraphSpacingAfter(5);
        this.radRichTextEditor1.Document.Selection.Clear();
    }
 
    private Telerik.WinForms.Documents.Model.RadDocument ImportHtml()
    {
        RadDocument document = null;
        HtmlFormatProvider provider = new HtmlFormatProvider();
        using (Stream stream = File.OpenRead(@"..\..\test.html"))
        {
            document = provider.Import(stream);
        }
        return document;
 
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
RichTextEditor
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or