Incorrect page numbers in Table of Contents

I am generating Word document that contains two table of contents. I have the following code to deal with table of contents:

document.updateFields();
document.updatePageLayout();

The resulting/generated document has incorrect page numbers in the tables of contents. After spending time and researching the forum for a solution I found some information referring to fonts. Seems like by default it refers to /usr/share/fonts which is empty in my case. I had to reset it to the different path:
FontSettings.getDefaultInstance().setFontsFolder(myNewPath, false);

After I added the above code to change font location, everything seems to work.

Here are the few questions I would like to receive the answers to:
  • Why do I need the fonts in order for TOC to work? Everything worked fine until I added support of TOC
  • Which font exactly is required?
  • Do the fonts required depend on the document itself?
I need to understand how it might affect the existing solution I have and documents that have been generated correctly so far.

Hi Olga,

Thanks for your inquiry.
O-L-G-A:
Which font exactly is required?
Do the fonts required depend on the document itself?
Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats (JPEG, PNG, PDF or XPS). You need to install fonts that are used in your document on the machine where you're converting documents to Pdf. Please refer to the following articles:

How Aspose.Words Uses True Type Fonts
O-L-G-A:
Why do I need the fonts in order for TOC to work? Everything worked fine until I added support of TOC
You are facing the incorrect page numbers in table of contents due to missing font. Please check "Font Availability and Substitution" in above article.

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.

Please let us know if you have any more queries.


Hi Tahir,


You don’t mention that DOCX requires fonts. I also have problem with TOC in DOCX document. It is also resolved when I set a font path. Why?

You mention that fonts are required to update page number related fields. I never had a problem with page numbers in the footer. Nether in DOCX, nor in PDF. I only have a problem now with incorrect page numbers in TOC. Why is it a case?


Hi Olga,

Thanks for your inquiry. If the fonts are not installed on the system, the editor MS Word or Open Office uses the default available fonts.

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Please attach the output Word/Pdf file that shows the undesired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.
  • Please share your working environment e.g. operating system, Jdk version etc.

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.