Hello,
We are evaluating the Office File API to create Word documents and PDF documents - a sample here is created with a competitors product.
https://www.centrel-solutions.com/media/xiaconfiguration/capabilities/activedirectory.pdf
The following sample code takes 10 seconds to generate a 200 page document - we'd like to make this faster.
We found that creating the table with the correct rows and columns then inserting text and images was much faster than appending rows and columns one at a time. The BeginUpdate() and EndUpdate methods seem to make some difference.
Are there any other improvements you can recommend?
Is there any way we can reuse images that are used multiple times in these tables - would that make it faster to remove the duplication?
C#
private void GenerateDocument()
{
Stopwatch stopwatch = Stopwatch.StartNew();
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
Document document = wordProcessor.Document;
document.BeginUpdate();
document.Unit = DevExpress.Office.DocumentUnit.Point;
document.CompatibilitySettings.CompatibilityMode = CompatibilityMode.Mode15;
for (int i = 0; i < 100; i++)
{
Section section = document.AppendSection();
Table table = document.Tables.Create(document.Range.End, 50, 5);
table.BeginUpdate();
for (int j = 0; j < 50; j++)
{
DocumentImageSource imageSource = DocumentImageSource.FromFile(@"D:\CENTRELSolutions\XIAConfiguration\ConfigurationServer\SourceCode\images\tables\BackupExecServer\NetworkSettings.png");
DocumentImage documentImage = document.Images.Insert(table.Rows[j].Cells[0].ContentRange.End, imageSource);
documentImage.Size = new SizeF(PixelsToPoints(16), PixelsToPoints(16));
document.InsertText(table.Rows[j].Cells[0].ContentRange.End, "Testing");
document.InsertText(table.Rows[j].Cells[1].ContentRange.End, "The performance");
}
table.EndUpdate();
}
document.EndUpdate();
String filename = @"C:\temp\document2.docx";
document.SaveDocument(filename, DocumentFormat.OpenXml);
Process.Start(filename);
stopwatch.Stop();
MessageBox.Show(stopwatch.Elapsed.TotalSeconds.ToString());
}
}
Code
Thanks,
Dave