Line Spacing

3 posts, 0 answers
  1. Matt
    Matt avatar
    7 posts
    Member since:
    Nov 2015

    Posted 21 Feb 2017 Link to this post

    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. Matt
    Matt avatar
    7 posts
    Member since:
    Nov 2015

    Posted 21 Feb 2017 Link to this post

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

  3. Hristo
    Hristo avatar
    1510 posts

    Posted 22 Feb 2017 Link to this post

    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()
            this.radRichTextEditor1.Document = this.ImportHtml();
            this.radRichTextEditor1.ChangeParagraphLineSpacing(1, LineSpacingType.AtLeast);
        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.

    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.
Back to Top