This is a migrated thread and some comments may be shown as answers.
Finer page break control for sl rich text
5 Answers 33 Views
This is a migrated thread and some comments may be shown as answers.
Jens
Top achievements
Rank 1
Jens asked on 14 Jan 2013, 12:28 PM
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

5 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 17 Jan 2013, 07:32 AM
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.

0
Jens
Top achievements
Rank 1
answered on 17 Jan 2013, 10:16 AM
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?
0
Petya
Telerik team
answered on 21 Jan 2013, 04:28 PM
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.

0
Jens
Top achievements
Rank 1
answered on 21 Jan 2013, 05:02 PM
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?
0
Petya
Telerik team
answered on 23 Jan 2013, 05:00 PM
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.

Asked by
Jens
Top achievements
Rank 1
Answers by
Boby
Telerik team
Jens
Top achievements
Rank 1
Petya
Telerik team
Share this question
or