We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Is both updateFields() and updatePageLayout() needed after document creation?

Hi,


We have a solution that creates a Aspose.words document, this solution might also merge other documents into a single word document. Afterwords it is either delivered as a doc/docx, or converted to pdf/epub etc.

After adding/merging everything, we do both doc.updateFields() and doc.updatePageLayout() before returning it to be converted or saved to file.

I noticed that both these functions are rather slow (takes 15-20 seconds each), are these necessary to run, and are both necessary?

All documents contains TOC and page numbers in header/footer of each page.

Hi Tor Henning,

Thanks for your inquiry. The Document.UpdateFields method updates the values of fields in the whole document.

When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.

There is no need to update fields after executing a mail merge because mail merge is a kind of field update and automatically updates all fields in the document.

This method does not update fields that are related to the page layout algorithms (e.g. PAGE, PAGES, PAGEREF). The page layout-related fields are updated when you render a document or call UpdatePageLayout. To update fields in a specific part of the document use UpdateFields.

Document.UpdatePageLayout method rebuilds the page layout of the document. This method formats a document into pages and updates the page number related fields in the document such as PAGE, PAGES, PAGEREF and REF. The up-to-date page layout information is required for a correct rendering of the document to fixed-page formats.

This method is automatically invoked when you first convert a document to PDF, XPS, image or print it. However, if you modify the document after rendering and then attempt to render it again - Aspose.Words will not update the page layout automatically. In this case you should call UpdatePageLayout before rendering again.

Hope this answers your query. Please let us know if you have any more queries.

Hi,


When i mention merging, i think of merging of multiple documents into a single document. All documents are created via Aspose, we never edit any documents from another source.

Based on this information, it appears that both functions should be used in our case?

Hi Tor Henning,

Thanks for your inquiry. Yes, you need to call both methods. Please let us know if you have any more queries.

Thank you for the confirmation. :slight_smile:

Hi Tor Henning,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.