我使用以下方法使用 MS Word Mail 合并生成 PDF 文档。“PaymentPlanDetails”有7050条记录,其数据模型有 9 个字符串字段、一个int字段、一个小数字段和一个DateTime字段。
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;
}
问题是代码在“<code>using (var pdfDocument = converter.ConvertToPDF(mergeDocument))”行中挂起1 分钟 15 秒。有没有办法加快这个过程?
到目前为止我已经尝试过:
“<a href="https://www.syncfusion.com/forums/138495/conversion-of-large-word-doc-to-pdf-is-very-slow-also-often-results-in-out- of-memory-errors" rel="nofollow noreferrer">https://www.syncfusion.com/forums/138495/conversion-of-large-word-doc-to-pdf-is-very-slow-also-often -results-in-out-of-memory-errors”一文展示了如何启用快速渲染。但是,在我当前使用的版本中,“converter.Settings”下没有列出这样的成员。