We are doing a large mail merge; a 10,000 page report. The report takes 8GB of memory to run and it produces a 50MB file. How do we lower the memory usage of the report? Our web server only has 4GB of memory.
Here is the code. The “Execute” line highlighted in yellow takes up 4GB of memory and the “Save” line also takes up 4GB of memory.
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
public void
SaveBuilder(string inputPath, string outputPath, List
list)
{
var license = new License();
license.SetLicense("Aspose.Total.Product.Family.lic");
var doc = new Document(inputPath);
try
{
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;
var dataTable = list.ToDataTable();
doc.MailMerge.Execute(dataTable);
doc.MailMerge.DeleteFields();
}
catch (Exception
exception)
{
ExceptionLogic.HandleException(exception);
throw;
}
try
{
using (var
fileStream = new FileStream(outputPath,
FileMode.Create))
{
doc.Save(fileStream, SaveFormat.Pdf);
fileStream.Close();
}
}
catch (Exception
exception)
{
ExceptionLogic.HandleException(exception);
throw;
}
}