Finer page break control for sl rich text

6 posts, 0 answers
  1. Jens
    Jens avatar
    3 posts
    Member since:
    Aug 2011

    Posted 14 Jan 2013 Link to this post

    I have a Silverlight application that uses the RadRichTextBox to allow the user to edit multiple sections.

    Now I want to generate a document that basically consists of all those sections concatenated, but the sections themselves shouldn't break on page breaks. It's not strictly necessary that the resulting document is a Telerik RadDocument, although that would be beneficial.

    Is there a straight-forward way to do this at all?

    Cheers, John
  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 17 Jan 2013 Link to this post

    Hello Jens,
    You can merge documents as shown in this forum thread.

    All the best,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Jens
    Jens avatar
    3 posts
    Member since:
    Aug 2011

    Posted 17 Jan 2013 Link to this post

    What makes this difficult is that it's necessary to avoid page breaks. Can I control a paragraph (or other unit of text) not be split up across pages?
  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 21 Jan 2013 Link to this post

    Hello John,

    I am having a hard time understanding your requirements. When you say you the sections themselves shouldn't break on page breaks, do you mean that the concatenated document should flow without page breaks in it? If this is the case, there is a pretty straightforward way to do that by setting the layout mode of the editor/document to Flow or FlowNoWrap.

    The other thing that comes to mind is that you would like that each section in your document takes up no more that one page regardless of how much contents a section contains, is that correct? If this is the case the solution might not be so easily implementable.

    If each section in your document contains less text than a single page, you can use the approach shown in Boby's post by inserting page/section breaks between your separate pieces of content (the document fragments).
    RadDocument mergedDocument = new RadDocument();
    foreach (var document in documents)
    {
        mergedDocument.CaretPosition.MoveToLastPositionInDocument();
        mergedDocument.InsertFragment(new DocumentFragment(document));
        mergedDocument.InsertPageBreak();
    }

    If not all sections can fit on a page, you can try setting different page sizes to the sections respectively to their contents. This can be done using the PageSize property of Section. However, in order to adopt such approach you should determine whether a section has more than one layout box, for example like this:
    if (section.GetAssociatedLayoutBoxes().Count() > 1)
    {
        //...change page size
    }

    The latter, however, might not work so well for very large sections.

    If I misunderstood you please elaborate a bit more on your requirements, so I can be of more help.
     
    Kind regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Jens
    Jens avatar
    3 posts
    Member since:
    Aug 2011

    Posted 21 Jan 2013 Link to this post

    I mean the second interpretation, no section should take up more than one page - at least in those cases where they can actually fit on a page, which is probably always the case.

    You proposed solution would of course fit this requirement, but another implicit requirement is that that a page should still contain as much sections as possible. Most of them will be about a fifth of a page and I don't want to have lots of almost-empty pages.

    MS Word has a feature to mark a paragraph as not to be broken up I believe.

    I reckon that this is something rather difficult to achieve?
  7. Petya
    Admin
    Petya avatar
    975 posts

    Posted 23 Jan 2013 Link to this post

    Hi Jens,

    Unfortunately, the scenario you are describing is currently not supported. The main limitation is that multiple sections cannot be added to a page, i.e. all members of the Telerik.Windows.Documents.SectionBreakType enum actually break the page, as well as the section. 

    When it comes to the Keep lines together option available for paragraphs in MS Word, it is indeed not implemented in RadRichTextBox. However, even if it was, if your document is built from multiple Sections with a single paragraph in each, it would not help you in implementing the desired behavior.

    However, if your document consists of one section or each section contains a large amount of paragraphs, you could workaround the problem using the following code:
    foreach (var paragraphs in editor.Document.EnumerateChildrenOfType<Paragraph>())
    {
        if (paragraphs.GetAssociatedLayoutBoxes().Count() > 1)
        {
            editor.Document.CaretPosition.MoveToInline(paragraphs.EnumerateChildrenOfType<Inline>().First());
            if (!editor.Document.CaretPosition.IsPositionInsideTable)
            {
                editor.InsertPageBreak();
            }
        }
    }
    Please bear in mind that the snippet is not thoroughly tested and might need additional tweaking.

    I hope this will help!
     
    Kind regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner