Get wrong page count

The actual page number is 16,but it is replace to be 17.
Here is the code and file.
image.png (31.4 KB)
paper.docx (1.3 MB)

DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToSection(doc.Sections.IndexOf(doc.FirstSection));
doc.FirstSection.Range.Replace(new Regex("[$]Assessment Pages", RegexOptions.Multiline), "",
    new FindReplaceOptions()
    {
        FindWholeWordsOnly = true,
        MatchCase = true,
        ReplacingCallback = new PageFiledReplacingCallback(builder)
    });
doc.UpdateFields();
public class PageFiledReplacingCallback : IReplacingCallback
{
    private DocumentBuilder _builder { get; set; }
    public PageFiledReplacingCallback(DocumentBuilder builder)
    {
        this._builder = builder;
    }

    public ReplaceAction Replacing(ReplacingArgs args)
    {
        if (args.Match.Success)
        {
            _builder.MoveTo(args.MatchNode);
            _builder.InsertField(FieldType.FieldNumPages, true);
            return ReplaceAction.Replace;
        }
        return ReplaceAction.Skip;
    }
}

@lkf77081 Unfortunately, I cannot reproduce the problem on my side using the latest 22.6 version of Aspose.Words for .NET.
Please note that NUMPAGES field is updates by Aspose.Words layout engine. To properly calculate the number of pages in the document, it requires the fonts used in your document. Otherwise Aspose.Words substitutes the fonts and this might lead into the layout difference between the original and Aspose.Words built layout.

Do fonts means “OpenDyslexic” ,“Braille29” or “Arial” below?
And will versions after 22.6 resolve the problem no matter whatever the font is?

if (isEnableFontStyle)
{
    var fontChanger = new DocumentFontChanger(null, specialFontStyle == Feature.Common.Service.Interface.FontStyle.Dyslexic ? "OpenDyslexic" : "Braille29");
    doc.Accept(fontChanger);
}
else
{
    //TODO special single-side paper markbox font style
    var fontChanger = new DocumentFontChanger(null, "Arial");
    doc.Accept(fontChanger);
}

@lkf77081

I mean Aspose.Words requires physical font files, they are required by Layout Engine to calculate size and position of glyphs in the document. Please see our documentation to learn where Aspose.Words looks for fonts.
You can check what fonts are substituted while building document layout by implementing IWarningCallback.

Any version of Aspose.Words requires fonts to build document layout properly.

the fonts i used is “OpenDyslexic” and “Arial” .
Arial is from the system,OpenDyslexic is in my project.
image.png (9.6 KB)
image.png (41.4 KB)

now i use the 21.5.0 , Have any plan to fix this issue after 22.6 version?

@lkf77081 To fix the problem we need to reproduce it first. But on my side NUMPAGES field is updated properly.
The only possible reason of the problem on your side might be font substitution. As I can see the following fonts are using in the source document:

  • Arial
  • Courier new
  • PMingLiU
  • Symbol

Have you tried converting your document to PDF in your environment? Since the same layout engine is used to render document to PDF and calculate number of pages in the document, the conversion will show where the problem is. Also, in this case you can use IWarningCallback, as I mentioned earlier to detect what fonts has been substituted.

paper.pdf (721.7 KB)
convert to pdf,but only left 5 page 。
“This document was truncated here because it was created in the Evaluation Mode.” i don’t understand what it mean。

@lkf77081 This means that you are using Aspose.Words in evaluation mode. In free evaluation more Aspose.Words has limitations - it injects evaluation version watermark and text and limits the maximum size of the document to several hundreds of paragraphs:
https://docs.aspose.com/words/net/licensing/#free-trial
You should apply the license before processing document.

i had license in my program,but it is expired.
will expired license have an affect on my issue?

@lkf77081 Every Aspose.Words license provides one year subscription for free update to any Aspose.Words version released during this time. If Aspose.Words version you are using in your application is released after the license expiration date, Aspose.Words will throw an exception on SetLicense.

Demo.docx (544.2 KB)
Demo.pdf (521.0 KB)
image.png (346.0 KB)

i find a new case for this issue.
the page count of Demo.docx is 15, but when it is turned to be a pdf ,the page count is 16, as image.png shows, the table at page 4 is changed to be at page 5 . can you help me check out the root cause ?

And another problem,i know aspose has different engines for word and PDF ,and the LayoutEnumerator use pdf engine , but when i check the PageIndex of elements at page 4 of the Demo.docx with LayoutEnumerator, i find that the table at bottom , it’s PageIndex is still 4, not 5 。
If LayoutEnumerator use pdf engine , i think the PageIndex should be 5,because the table is at page 5 when turned to be a PDF。 i am confused,so why is it like this ?

waiting for your reply,thanks

@lkf77081
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25382

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as WORDSNET-25382) have been fixed in this Aspose.Words for .NET 23.7 update also available on NuGet.