Size Limit for Mail Merge

Hi,

I have a problem in doing mail merge.

Word document is saved in database as BLOB ( SQL Server)

(my.doc size is 108MB.)

During the execution this is the code we have

fileName1 is the actual BLOB Saved

Dim templateDocument As Document
Dim srcDocStream As New MemoryStream(fileName1)
templateDocument = New Document(srcDocStream)

at this line - its throwing Error –

Exception of type 'System.OutOfMemoryException' was thrown.

is there a Limit on the document size - -if there is what is the size and how to increase it

Please Help

Vijay

Hi Vijay,

Thanks for your inquiry.

Although your document size seems rather large, I don’t think Aspose.Words has any limitation in the size of document being loaded. The only limiation might be RAM. Could you please post your deployment computer’s specs here.

Also please post the full code you are using here, there might be a small issue in your code somewhere somewhere causing this exception down the line.

Thanks,

to add to my question -

we save the letter as BLOB in database

we use View to merge the data

then we save it to temporary location

then we open the file

please let me know if you need any more information.

Protected Sub ExecuteLink_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExecuteLink.Click
Dim viewName As String = String.Empty
Dim ds1 As DataSet
Dim fileName1() As Byte
Dim viewDataTable As DataTable
Dim viewRow As DataRow
Dim nameIndex As Integer
Dim documentName As String
Dim selectedFormLetterName As String = String.Empty
Dim resourceid As String = String.Empty 
ds1 = FormLetterMaintenanceServices.CreateFormLetterData(formLetterIds)
For Each dr1 As DataRow In ds1.Tables("Resources").Rows
resourceid = dr1("resourceid").ToString() 'TG 6538/IPMGR-730
viewName = dr1("DATASOURCE").ToString
selectedFormLetterName = dr1("FORMLETTERNAME").ToString()
If dr1("FORMLETTERFILE").ToString.Length > 0 Then
fileName1 = dr1("FORMLETTERFILE")
Dim srcDocStream As New MemoryStream(fileName1)
' sometimes its failing here to create it as document-** 'System.OutOfMemoryException
templateDocument = New Document(srcDocStream)
End If
Next
keyField = String.Concat(ipTypeName.Remove(ipTypeName.Length - 1, 1), FormLetterConstants.Id)
viewDataTable = FormLetterServices.GetViewData(viewName, keyField, masterID, Session("userID"))
viewRow = viewDataTable.Select(keyField & " = " & masterID)(0)
'Here I merge the data -** 'System.OutOfMemoryException
templateDocument.MailMerge.Execute(viewRow)
documentName = selectedFormLetterName.Split(".doc")(0) & "_" & dateStamp & "_" & masterID & ".doc"
Dim fileName As String = System.IO.Path.Combine(FormLetterServices.GetPath(), "Temporary\" & documentName)
' sometimes its failing here to save -** 'System.OutOfMemoryException
templateDocument.Save(fileName)
If (transferFileToClient) Then
Response.Clear()
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.AppendHeader("content-disposition", "attachment; filename=" & documentName)
Response.CacheControl = "public"
Response.ContentType = "application/vnd.ms-word"
Dim bytes() As Byte
Using fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs)
bytes = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
End Using
Response.BinaryWrite(bytes)
Response.End()
End If
End Sub

Hi Vijay,

Thanks for your request. Memory usage depends on document size, format and document’s content. Usually Aspose.Words needs few times more memory than document size to build model of the document in memory. For example if your document’s size is 1 MB, Aspose.Words needs 10-20 MB of RAM to build its DOM in memory.

Also, I would like to say that producing huge MS Word documents is not very good practice. MS Word does not like huge documents. Usually it takes a lot of time to open such documents in MS Word and sometimes MS Word just hangs. Normal size of MS Word documents is 100 – 200 pages.

So the only way to work the problem around, I can suggest you, is producing few small documents instead of one huge document.

Best regards.

Hi Alexey,

so is there any way we can execute a file of that size 100mb +

Is there an established size limit that the document object can handle?

and can we increase the limit?

Please let me know

Kind Regards,

Vijay

Hi Vijay,

Thanks for your inquiry. There is no limit of document size in Aspose.Words. As Adam already mentioned, the only limit is amount of RAM on your PC.

Best regards,

Hi Vijay,

I just want to add, there are a few possible ways you could get your large document working on your PC:

  1. As Alexey mentioned, split your document in to more managable sized chunks. You can automate the spliting of the document through code.
  2. Assuming that you have a large amount of RAM but are still running out of memory during runtime then you most likely are running a 32 bit enviroment. I believe you can try using the /3GB switch to increase the avaliable RAM and this might just help in your situation.
  3. Upgrade to 64bit enviroment and/or increase RAM.

Thanks,