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

Free Support Forum - aspose.com

Aspose.Words Out of Memory Issue Mail Merging 6000 records

Hello,

We have been using Aspose.Words for about a year without issue. However, we have a need to take a word document and mail merge about 10,000 records and then we stream it as a PDF. The end result is a PDF with 10,000 pages all mail merged. When we try to do this, we get OutOfMemory errors every time. I’m guessing because the size of the document is too large. However, is a 10,000 page document really too large? I tried reducing it to 6,000 pages with the same Out of Memory error results.We have fairly decent test servers with 8GB RAM, so I’m fairly confident that it should be able to handle it.

We are using ASP.NET and we are simply building a DataTable with 10 columns and 6,000 rows of data. Then we call it as follows:

Dim dt as new DataTable(“OSHA300”)
.
. populate dt with sql select query (ex: select StoreNo, City, State, Zip FROM Store). This returns about 6,000 reocrds.


Dim doc As New Document(“C:\OSHA300A.DOCX”)
doc.MailMerge.Execute(dt)

doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveUnusedFields
doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveUnusedRegions
doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs
doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveContainingFields

I’m looking for a solution to this issue. The Out of Memory errors are not good as this is probably doing more harm to the server than we know. Here are my questions:

1) Has anyone had this issue before and how did you correct it?
2) Is it possible to merge 200 records at a time and process the document in chunks? Basically, merge the first 200 records, create a PDF, then process the next 200 records, and append them to the original PDF, etc… then stream the final PDF to the browser? Or would streaming a large PDF cause the same out of memory issues?
3) I’ve attached our word doc to this forum if it helps in recreating this issue.

Any help would be greatly appreciated as we need to decide if we should continue with Aspose.Words or start looking for a new solution.

Thanks,
Brian

Hi Brian,

Thanks for your inquiry. Please note that performance and memory usage all depend on complexity and size of the documents you are generating. While rendering a document to fixed page formats (e.g. PDF), Aspose.Words needs to build two model in the memory – one for document and the other for rendered document.

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 perform the mail merge in several steps with generating several result Pdf documents on reduced number of records. After saving the multiple Pdf files, please
concatenate them using Aspose.Pdf. Moreover, please try running the application with more RAM. Hope this helps you.