How to merge multiple RadDocuments into one RadDocument?

7 posts, 0 answers
  1. Pawan
    Pawan avatar
    7 posts
    Member since:
    Mar 2012

    Posted 14 May 2012 Link to this post

    Hello All,

    I have a requirement to print a number of RTF notes as a single document. I tried to create a RadDocument for each note and merge them, but unable to get it done.
    Please guide me through the appropriate way to achieve this functionality.

    Thanks
    Pawan
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 17 May 2012 Link to this post

    Hello Pawan,

    Thank you for writing.

    You can merge documents by creating a new RadDocument instance and creating copies of the sections from the documents that you want to merge:
    private RadDocument MergeDocuments(RadDocument[] documents)
    {
        RadDocument mergedDocument = new RadDocument();
      
        foreach (RadDocument document in documents)
        {
            foreach (Section section in document.Sections)
            {
                Section copySection = section.CreateDeepCopy() as Section;
                document.Sections.Remove(section);
                mergedDocument.Sections.Add(copySection);
            }
        }
      
        return mergedDocument;
    }

    I hope this helps. 

    Kind regards,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Pawan
    Pawan avatar
    7 posts
    Member since:
    Mar 2012

    Posted 05 Jun 2012 Link to this post

    Hello Svett,

    Thanks for your reply.
    The solution you suggested worked great.

    Now, one more thing is needed: the functionality I need to develop, should show all the notes in a paged manner ie. a clear gap between two notes. By the help of your code snipped, I am able to generate a single document from all notes, but no distinction is visible between two notes in merged document. I tried to insert a Page Break, but that inserted in the beginning of the document.

    So, if you can suggest any way to show a clear distinguishable pages in the merged document, it would be a great help.

    Thanks
    Pawan
  5. Svett
    Admin
    Svett avatar
    728 posts

    Posted 08 Jun 2012 Link to this post

    Hello Pawan,

    Presently, you cannot achieve such separation because of an issue in RadRichTextBox, which does not allow to insert page break at the last position. I added it to our public issue tracking system. Meanwhile, you can insert text between each document.

    I updated your Telerik points.

    Regards,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  6. Kshitij
    Kshitij avatar
    1 posts
    Member since:
    Sep 2012

    Posted 11 Sep 2012 Link to this post



    You can add a new section (a blank section) after copying the original sections of each document. This creates some separation between different sections. Hope that helps.

    foreach (RadDocument document in documents)
    {
        Section dummySection = new Section();
        foreach (Section section in document.Sections)
        {
            Section copySection = section.CreateDeepCopy() as Section;
            document.Sections.Remove(section);
            mergedDocument.Sections.Add(copySection);
        }
        mergedDocument.Sections.Add(dummySection);
    }

  7. Rajiv
    Rajiv avatar
    1 posts
    Member since:
    Feb 2012

    Posted 14 Jul in reply to Kshitij Link to this post

    Hi Kshitij,

    Copying section creates a new page. I am trying to go one level deeper (block level) but copying block creates an empty line between blocks. Can you please guide me how to avoid creating empty lines while copying blocks. Can I go one more level deep on elements level. 

    Sample code 

                     foreach (Section _section in _componentDocument.Sections)
                            {
                                foreach (Block _block in _section.Blocks)
                                {
                                    Block copyBlock = _block.CreateDeepCopy() as Block;
                                    masterSection.Blocks.Add(copyBlock);
                                    copyBlock = null;
                                }
                            }
                         

    Really appreciate your help and support.

    Rajiv Jain

  8. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 15 Jul Link to this post

    Hello Rajiv,

    Thank you for writing. 

    It is normal that the Block elements are separated by an empty line. The Paragraph is a derivative of Block. Inline elements , e.g. Span, represents an inline object that allows you to display formatted text. The Spans can only be used in the context of a Paragraph class. As the spans are inline elements they get placed one after another and the text inside them gets wrapped to the next line if the space is insufficient. You can iterate all sections in a document, traverse all paragraphs in a section and copy each span from the paragraph and add it to the result document. Thus, no empty lines will be added.
     
    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready