I use the following method to generate a PDF document using MS Word Mail merge. The “PaymentPlanDetails” has 7050 records and its data model has 9 string fields, an int field, a decimal field and a DateTime field.
private MemoryStream MergeOracleDisbursementToPdf(OracleDisbursementsHeader mailMergeModel, List<OracleDisbursementsDetailPDF> PaymentPlanDetails, byte[] fileBytes)
{
if (fileBytes == null || fileBytes.Length == 0)
{
return null;
}
var templateStream = new MemoryStream(fileBytes);
var pdfStream = new MemoryStream();
var wordStream = new MemoryStream();
WordDocument mergeDocument = null;
using (mergeDocument = new WordDocument(templateStream, FormatType.Docx))
{
if (mergeDocument != null)
{
var mergeList = new List<OracleDisbursementsHeader> { mailMergeModel };
var reportDataSource = new MailMergeDataTable("Report", mergeList);
var tableDataSource = new MailMergeDataTable("PaymentPlanDetails", PaymentPlanDetails);
List<DictionaryEntry> commands = new List<DictionaryEntry>();
commands.Add(new DictionaryEntry("Report", ""));
commands.Add(new DictionaryEntry("PaymentPlanDetails", ""));
MailMergeDataSet ds = new MailMergeDataSet();
ds.Add(reportDataSource);
ds.Add(tableDataSource);
mergeDocument.MailMerge.ExecuteNestedGroup(ds, commands);
mergeDocument.UpdateDocumentFields();
using (var converter = new DocIORenderer())
{
converter.Settings.
using (var pdfDocument = converter.ConvertToPDF(mergeDocument)) // takes 1 Min 15 Secs for 7050 Records
{
pdfDocument.Save(pdfStream);
pdfDocument.Close();
}
}
mergeDocument.Close();
}
}
return pdfStream;
}
The issue is the code hangs in the line of “using (var pdfDocument = converter.ConvertToPDF(mergeDocument))
” for 1 Minute and 15 Seconds. Is there a way to speed up this process?
What I have tried so far:
“https://www.syncfusion.com/forums/138495/conversion-of-large-word-doc-to-pdf-is-very-slow-also-often-results-in-out-of-memory-errors” article shows how to enable fast rendering. However, in the version that I am currently using, has no such member listed under “converter.Settings”.