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

Free Support Forum - aspose.com

Issue with mail merge having multiple attachment with sized up to 1.5 GB

Hello,
I am using mail merge with multiple attachments, however, I am facing some issues. Currently, while merging many attachments (size up to 1.5 GB approximately), it uses full RAM of the system and process gets stuck at some points and fails to complete. It is working fine with attachment up to 1GB.
So, my question is, can we use network path for attachment and directly use the path to mail merge process.
Please help me.

Thanks,

@NanduNairSigma

Yes, you can use network path to import document into Aspose.Words’ DOM.

Please note that performance and memory usage all depend on complexity and size of the documents you are generating.

In terms of memory, Aspose.Words does not have any limitations. If you’re loading huge Word documents into Aspose.Words’ DOM, more memory would be required. This is because during processing, the document needs to be held wholly in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

In your case, we suggest you please use SaveOptions.TempFolder property to specify the folder for temporary files used when saving to a DOC or DOCX file. Hope this helps you.

Hi Tahir,

We can use SaveOptions.TempFolder, but does that move the merge process to a temp folder and not use memory? Want to understand what exactly does it do. We are trying to offload as much as we can to the disk and not use memory. Goal is that we load the main word document, then load all additional documents from a network path, and add it to the main document. As it adds to the main document we want that merged doc to be written to the disk (while it is being processed) so that we don’t end up with massive memory footprint.

@pparikh

In your case, you need to increase the memory size. Aspose.Words does not use the disk while importing and joining documents.

When Aspose.Words saves a document, it needs to create temporary internal structures. By default, these internal structures are created in memory and the memory usage spikes for a short period while the document is being saved. When saving is complete, the memory is freed and reclaimed by the garbage collector.

If you are saving a very large document (thousands of pages) and/or processing many documents at the same time, then the memory spike during saving can be significant enough to cause the system to throw OutOfMemoryException. Specifying a temporary folder using TempFolder will cause Aspose.Words to keep the internal structures in temporary files instead of memory. It reduces the memory usage during saving, but will decrease the save performance.

The folder must exist and be writable, otherwise an exception will be thrown.

Hi Tahir,

We have use SaveOptions.TempFolder while saving doc. We can not see any changes on that temp folder. How we can test that Tempfolder is actually used or not? We have also try with TempFolder = “” but it did not throw any error. So, Need to check that it actually working for us or not.

Please help.

Thanks.

@NanduNairSigma

Perhaps, you are testing this property with small size document. Please test it with a very large size document (thousands of pages).

Hi Tahir,

We have tried with 2500 pages document. But the result is the same. We cannot see any changes on the temp folder. Please find attached code and give your input.

Thanks,

@NanduNairSigma

Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

If your document’s size is big, please upload it to Dropbox and share the download link here for testing.

Hi Tahir,

Attached Dropbox link for console app and document. Please check project and give your input.

Thanks.

@NanduNairSigma

In your code, you are saving document to PDF. Please note that SaveOptions.TempFolder specifies the folder for temporary files used when saving to a DOC or DOCX file.

@tahir.manzoor
Are there any options on how to optimize this for PDF? We are seeing a huge memory footprint. Original document is a .DOC/.DOCX and after mail merge we output as PDF, what other options are available to avoid so much memory usage

@pparikh

You can use SaveOptions.MemoryOptimization property for memory optimization. Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time.

Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "SaveOptions.MemoryOptimization.doc");
// When set to true it will improve document memory footprint but will add extra time to processing. 
// This optimization is only applied during save operation.
SaveOptions saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Pdf);
saveOptions.MemoryOptimization = true;

doc.Save(MyDir + "SaveOptions.MemoryOptimization.pdf", saveOptions);