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
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
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
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.
Svett
the Telerik team
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);
}
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
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
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