Page numbers insertion is slow

Dear Sir or Madam,


I build a document by writing directly to the DOM. The document contains pretty few sections and it takes 2 minutes to achieve the task on my laptop. Recently I was asked to add page numbers in the document. As I do not use DocumentBuilder I did it using a workaround:
For each section inserted in the document I go to the last paragraph of footers of last section and add the field:
DocumentBuilder documentBuilder = new DocumentBuilder(mOutputDocument); documentBuilder.MoveTo(mOutputDocument.LastSection.HeadersFooters[footerType].LastParagraph);
documentBuilder.InsertField(fieldBody);
The document processing time increased from 2 minutes to 10(!) minutes. I tried to use a different approach: enumerate through all the sections in the output document and add page numbers in each section but it took even longer. Is there any way I can speed up the page numbers insertion? Document in attach is the one I try to build.

Hi Alex,


Thanks for your inquiry. Most likely what is causing the slowdown is that the first overload of InsertField will update the field at the same time and with PAGE field this can often mean building the page layout in memory which although fast, in this case might stack up and be causing the slow down you are experiencing. To try solve the issue please replace any instance of builder.InsertField(“PAGE”); with builder.InsertField(“PAGE”, null); and see if that helps.

Best regards,

Thank you Awais , it helped!


Regards,
Alex