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

Seperate single Word document into multiple RadDocuments

5 Answers 193 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Ellis
Top achievements
Rank 1
Richard Ellis asked on 24 Jan 2011, 04:42 PM
Hi

We are looking to use the Telerik RichTextBox for Silverlight in our product, but are having trouble coding the following.

As part of our CMS for our product we would like to allow a single RadDocument to be loaded from a Word file which we could then split up into multiple Documents to be edited separately in the UI.  This would ideally be split up based on the 'Pages' (as determined by Word Page Breaks or sections) when the document is originally created in Word.

I was hoping that the Page breaks/Sections in Microsoft Word would load into the RadDocument as separate Sections, however this does not seem to be the case.

Any ideas?

Thanks.

5 Answers, 1 is accepted

Sort by
0
Richard Ellis
Top achievements
Rank 1
answered on 25 Jan 2011, 10:27 AM
Looks like char 9674 (Lozenge) is used for page breaks. Although this does mean it can't be used in the Word document being uploaded without adding an extraneous page break.

Still, now I can move on with my life.
0
Boby
Telerik team
answered on 27 Jan 2011, 05:52 PM
Hi Richard Ellis,
You can achieve this by iterating through document inlines and searching for page breaks. When page break is found,  create document selection and extract document from it. Following is a sample code for extracting the first one (easily expandable for extracting all pages):
private static RadDocument ExtractFirstPageDocument(RadDocument document)
{
    DocumentPosition position = new DocumentPosition(document);
    document.Selection.SetSelectionStart(position);
 
    while (position.MoveToNextInline())
    {
        InlineLayoutBox inlineBox = position.GetCurrentInlineBox();
 
        if (inlineBox.IsFormattingSymbol)
        {
            FormattingSymbolLayoutBox formattingSymbolBox = (FormattingSymbolLayoutBox)inlineBox;
            if (formattingSymbolBox.FormattingSymbol == FormattingSymbols.PageBreak)
            {
                break;
            }
        }
    }
 
    document.Selection.AddSelectionEnd(position);
    RadDocument page1Document = document.Selection.CreateDocumentFromSelection();
 
    return page1Document;
}

Don't hesitate to contact us if you have other questions.


Greetings,
Boby
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richard Ellis
Top achievements
Rank 1
answered on 31 Jan 2011, 12:28 PM
Thanks for this, but it seems to result in the following InvalidCastException:
Unable to cast object of type 'Telerik.Windows.Documents.Model.Paragraph' to type 'Telerik.Windows.Documents.Model.Inline'.

Any idea what could cause this?
0
Richard Ellis
Top achievements
Rank 1
answered on 31 Jan 2011, 12:40 PM
I've also found that a Page Break can be included with text within the same inline (possibly depends on the type of break/section/or the formatting applied) and in these cases the Page Breaks are not found using your method above/below.  This also resulted in a StackOverflowException on one document.
0
Boby
Telerik team
answered on 02 Feb 2011, 01:34 PM
Hello Richard Ellis,
Thank you for the feedback. Could you please open a support ticket from your Telerik account and send us attached a sample document that causes InvalidCastException? Another document containing page break as part of other inline will also help us to investigate the problem further.

Greetings,
Boby
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
RichTextBox
Asked by
Richard Ellis
Top achievements
Rank 1
Answers by
Richard Ellis
Top achievements
Rank 1
Boby
Telerik team
Share this question
or