Seperate single Word document into multiple RadDocuments

6 posts, 0 answers
  1. Richard Ellis
    Richard Ellis avatar
    26 posts
    Member since:
    Mar 2010

    Posted 24 Jan 2011 Link to this post

    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.
  2. Richard Ellis
    Richard Ellis avatar
    26 posts
    Member since:
    Mar 2010

    Posted 25 Jan 2011 Link to this post

    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.
  3. Boby
    Admin
    Boby avatar
    763 posts

    Posted 27 Jan 2011 Link to this post

    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>>
  4. Richard Ellis
    Richard Ellis avatar
    26 posts
    Member since:
    Mar 2010

    Posted 31 Jan 2011 Link to this post

    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?
  5. Richard Ellis
    Richard Ellis avatar
    26 posts
    Member since:
    Mar 2010

    Posted 31 Jan 2011 Link to this post

    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.
  6. Boby
    Admin
    Boby avatar
    763 posts

    Posted 02 Feb 2011 Link to this post

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