RTF table borders lost on import

3 posts, 1 answers
  1. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 20 Feb 2013 Link to this post

    I am trying to build a RadDocument from multiple RTF strings. Tables are imported correctly except the borders are lost. The borders displayed correctly when viewed in MS Word. Is there a better way to do this?

    foreach (string rtfTextString in myListOfStrings)
    {
        RtfFormatProvider provider = new RtfFormatProvider();
        RadDocument  subDoc = provider.Import(rtfTextString);
      
        foreach (Section s in subDoc.Sections)
        {
            var copy = s.CreateDeepCopy() as Section;
            if (copy != null)
            {
                richTextBox.Document.Sections.Add(copy);
            }
        }
    }
  2. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 21 Feb 2013 Link to this post

    Nevermind. I found the posts about InsertFragment. I had tried that before, but got null reference exceptions. Then I saw a post about having to Measure and Arrange before calling InsertFragment.

    MeasureAndArrangeInDefaultSize(doc);
      
    doc.CaretPosition.MoveToLastPositionInDocument();
    doc.InsertFragment(new DocumentFragment(subDoc));

    Now it works great. You should add the bit about Measure and Arrange to your documentation.
  3. DevCraft banner
  4. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 25 Feb 2013 Link to this post

    Hello John,

    I am glad you were able to resolve the issue you were facing.

    Generally, the latter approach - inserting a document fragment, is the recommended one as creating deep copies of sections and adding them to a measured document (in that case - the one shown in the editor) using the Sections collection might cause issues.

    As for your comment about the exception you were observing - I was unable to reproduce it. However, you should indeed call the method when creating a document from code prior to inserting in it. 

    Let us know if you need further assistance.
     
    Kind regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top