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

Free Support Forum - aspose.com

Bug in Table Of Contents page numbers when generating word from template

Me and my team members experience a problem we believe is a bug - we use Aspose.Words to generate a word document from a template, and we end up with wrong page number in the table of contents (TOC) that is solved only by manually update the TOC.

We use the library in Dotnet core container, and this bug also reproduce on our MAC development PCs.

I attached a ZIP file with a small program that reproduces the bug.
In order to run it you should add the license file, run it in CLI and check the generated document.
The zip contains the current word document with wrong page numbers, and contains a clear readme of how to run (although it’s straightforward).

Looking forward for support,
Thanks,
Roni

ReproduceTOCPagingBug.zip (206.0 KB)

@Ronim

We have tested the scenario using the latest version of Aspose.Words for .NET 20.8 and have not found the shared issue. So, please use Aspose.Words for .NET 20.8. We have attached the output DOCX with this post for your kind reference.
20.8.zip (88.2 KB)

Hi Tahir, Thanks for the quick response.
However, It didn’t solve my problem, as you can see in the ZIP I attached we are already using version 20.8 - as can be seen in the csproj file :

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp3.1</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Aspose.Words" Version="20.8.0" />

Can you suggest another reason why it happens ?

@Ronim

Could you please share the following detail for further testing?

  1. Screenshot of table of content.
  2. Problematic output document generated by Aspose.Words 20.8.
  3. Please download the shared document in my previous post and check if it is correct output.
  4. Please update the TOC field at your using using MS Word and share the expected output document.

We will investigate the issue and provide you more information on it.

Hi,
Please see attached :

  1. document TOC screenshot
  2. example_for_mismatch_page_numbers_in_generated_report.docx - This is the report generated by Asspose with the bug
  3. example_for_mismatch_page_numbers_in_generated_report_after_manual_update.docx - this is the same report after I manually update TOC (right click update and choosing entrire table)
  4. I checked the document you attached and it looks like it is correct and doesn’t have the bug in it.
  5. Note that we’re using dotnet core docker container. I created the example project inside a container I already have with more applications, so it will be hard to share the Dockerfile as is, but I copied the relevant part from it so you could modify it and build a container :
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
RUN apt-get update && apt-get install -y libfontconfig1 \
    && rm -rf /var/lib/apt/lists/*
COPY . .
RUN dotnet restore
RUN dotnet publish -c release -o /app
WORKDIR /app
COPY ./<Example Project Directory>

TOCBugData.zip (293.7 KB)

@Ronim

It looks like this issue is not related to Aspose.Words. The page number of last TOC item is 6. When you click on this link, you will notice that MS Word moves the cursor to 6th page. However, MS Word incorrectly updates the page number to 5.

ReproduceTOCPagingBugWorse.zip (310.3 KB)

Hi Tahir,
We managed to reproduce the issue with another template in a way that it’s more significant and it can be seen it’s not an MS Word issue - in this example, you can see the TOC tells us the last paragraph is on page 21 although there are only 16 pages in the document (including page 0 which is the page that MS word is not numbering).
See the updated project and outcome document attached.
Please advise, Thanks,
Roni

@Ronim,

Unfortunately, we are unable to download the ZIP file. Please ZIP and attach the documents again. Thanks for your cooperation.

ReproduceTOCPagingBugWorse.zip (310.3 KB)

Uploaded again

@Ronim,

We have logged this problem in our issue tracking system as WORDSNET-21061 . You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@Ronim

The issue you are facing is actually not a bug in Aspose.Words. So, we have closed this issue WORDSNET-21061 as ‘Not a Bug’.

Please install all fonts used in your document at MAC system to get the desired output. You can implement IWarningCallback interface and save document to PDF to get notification for missing fonts on your system.

Hello Tahir,
I didn’t understand how the table of content issue is related to fonts.
Can you tell me which fonts are missing and how would it help ?

@Ronim

The page numbers of table of content are related to page layout of document. If the fonts are not installed on the system, the page layout will be incorrect and page numbers will also be incorrect. To check this scenario, you can implement IWarningCallback interface and save the document to PDF for missing font notification. The page layout of PDF document will be incorrect if the fonts are missing on the system.