Word pages count is not correct

Dears,
We are facing issue with Aspose.Word:
the page count for word file is not correct when we try to access Pages Preoperties for Document Object, below is our sample of C# code:

var docPath = "[path]"
WordDocument doc = new WordDocument(docPath);
doc.PageCount=4; //but actually it is only 3

we are using Aspose.Words version 23.7
and our sample contians logo image in header and footer section plus a signature image at the end of the document.
attached is the word sample that we used

samplepagecount.docx (330.2 KB)

Appreciated your help!

Regards

@atalal AL-Mohanad font is used in your document, but this font is not availabe on my side. Could you please attach this font here for testing.

To calculate number of pages in the document, Aspose.Words required font used in the document. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout differences due to the different fonts metrics and as a result incorrect page count. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to lean where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/

Thanks for your quick reply below is the font required

al-mohanad-regular_1.zip (44.5 KB)

@atalal Except the missed font, the problem occurs because by default MS Word uses font open type features. Aspose.Words.Shaping.Harfbuzz package provides support for OpenType features in Aspose.Words using the HarfBuzz text shaping engine. You should enabling open type features to get the expected result. To achieve this you should add reference to Aspose.Words Shaping Harfbuzz plugin and use the following code to calculate page count:

Document doc = new Document(@"C:\Temp\in.docx");
doc.FontSettings = new FontSettings();
// "C:\Temp\fonts" folder contains 'AL-Mohanad' font
doc.FontSettings.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(@"C:\Temp\fonts", true) });
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
Console.WriteLine(doc.PageCount); // Returns 3

Thanks a lot Mr. Alexey! , you save my day appreciated you quick help and support.

1 Like