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”.
EnableFastRendering member is not listed in "converter.settings": By default we have used Fast rendering approach in Portable platforms (Asp.Net Core and Xamarin) while performing Word to PDF conversion and so this "EnableFastRendering" property is not listed in these platforms. But we have provided this Fast rendering approach as an option in Base platforms (Windows Forms, WPF, Asp.Net Web Forms) while performing Word to PDF conversion and so it is listed in these above mentioned Base platforms.
Suggestion to improve performance: We suggest you to use x64 processor to utilize the available RAM and reduce the execution time.
If you are still facing the same problem means, kindly provide us the following details from your end:
Based on the above details, we will analyze further on the reported problem and will provide you the appropriate solution at the earliest.
Note: I work for Syncfusion