We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merging RTF Documents

Hi,

I want merge two rtf documents into one rtf document. I have seen following piece of code that merges two doc documents. Do I need to use same method to merge rtf documents by passing rtf documents in the AppendDocument method?

string dataDir = RunExamples.GetDataDir_QuickStart();

string fileName = “TestFile.Destination.doc”;

// Load the destination and source documents from disk.

Document dstDoc = new Document(dataDir + fileName);

Document srcDoc = new Document(dataDir + “TestFile.Source.doc”);

// Append the source document to the destination document while keeping the original formatting of the source document.

dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);

dstDoc.Save(dataDir);

Console.WriteLine("\nDocument appended successfully.\nFile saved at " + dataDir);

By using the above code, I am seeing that merging two doc documents of size 2 MB and 5 MB resulted in merged document of around 19 MB.

By using the above code and passing rtf documents, merging two rtf documents of size 160 KB and 178 KB resulted in merged document of around 4 MB.

Also, If I want to load from stream instead of document and then merge those streams, Is there any method in aspose.word that supports this functionality?


Hi Muzna,

Thanks for your inquiry.
Muzna Tariq:
I want merge two rtf documents into one rtf document. I have seen following piece of code that merges two doc documents. Do I need to use same method to merge rtf documents by passing rtf documents in the AppendDocument method?
Yes, you can use the Document.AppendDocument for RTF documents. You can join the documents mentioned in following link using this method.
LoadFormat Enumeration
Muzna Tariq:
Also, If I want to load from stream instead of document and then merge those streams, Is there any method in aspose.word that supports this functionality?
Yes, you can import the documents from stream into Aspose.Words' DOM and merge them. Please refer to the following article:
Open Document from a Stream
Muzna Tariq:
By using the above code, I am seeing that merging two doc documents of size 2 MB and 5 MB resulted in merged document of around 19 MB.
By using the above code and passing rtf documents, merging two rtf documents of size 160 KB and 178 KB resulted in merged document of around 4 MB.
Could you please attach your input Word documents here for testing? We will investigate the issue on our side and provide you more information.

Hi,

Thanks for your feedback. I have successfully merged two rtf documents into one rtf document using AppendDocument method of Aspose.word.

Performing merging on two documents of around 62 KB and 318 KB took 29 seconds but the output document is 1.4 MB. I have attached input rtf documents and its merged output document. Please have a look.


Sorry for inconvenience.
Performing merging on two documents of around 62 KB and 318 KB took 2 seconds but the output document is 1.4 MB. I have attached input rtf documents and its merged output document.
Please have a look.
Hi Muzna,

Thanks for sharing the detail. Please note that Aspose.Words mimics the same behavior as MS Word does. If you join the RTF documents using MS Word, you will get the same output.

Please use RtfSaveOptions.ExportCompactSize property as shown below to reduce the size of output RTF. This property allows to make output RTF documents smaller in size, but if they contain RTL (right-to-left) text, it will not be displayed correctly. Hope this helps you.

Document doc1 = new Document(MyDir + "input1.rtf");

Document doc2 = new Document(MyDir + "input2.rtf");

doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);

RtfSaveOptions options = new RtfSaveOptions();

options.ExportCompactSize = true;

doc1.Save(MyDir + "17.6.rtf", options);

Hi Tahir,


Thank you for your feedback.
Using RtfSaveOptions.ExportCompactSize reduced the output RTF document. Performing merging on two documents of around 62 KB and 318 KB now results in output document is around 550 KB by using RtfSaveOptions.ExportCompactSize.

Regards,
Muzna
Hi Muzna,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.