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

How to merge multiple RadDocuments into one RadDocument?

8 Answers 662 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Pawan
Top achievements
Rank 1
Pawan asked on 14 May 2012, 03:09 PM
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

8 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 17 May 2012, 01:20 PM
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 >>
0
Pawan
Top achievements
Rank 1
answered on 05 Jun 2012, 12:55 PM
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
0
Svett
Telerik team
answered on 08 Jun 2012, 12:39 PM
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 >>
0
Kshitij
Top achievements
Rank 1
answered on 11 Sep 2012, 11:26 AM


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);
}

0
Rajiv
Top achievements
Rank 1
answered on 14 Jul 2016, 04:13 PM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Jul 2016, 01:57 PM
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 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.
0
Jeffrey
Top achievements
Rank 1
answered on 30 Oct 2018, 01:39 AM
Is there a way to merge these documents without having section breaks. When I do this the documents are merged but each ends up being on separate page when I would ideally like them merged one after the other with a space between. Thanks
0
Tanya
Telerik team
answered on 01 Nov 2018, 03:27 PM
Hello Jeffrey,

With the current version of RadRichTextEditor, you can merge the document using RadDocumentMerger, which exposes options for specifying whether a section break should be inserted or not, as well as of which type it should be. You can find more information about this functionality in the Append Documents help topic.

Hope this is helpful.

Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Pawan
Top achievements
Rank 1
Answers by
Svett
Telerik team
Pawan
Top achievements
Rank 1
Kshitij
Top achievements
Rank 1
Rajiv
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Jeffrey
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or