getPageCount issue

I used the attached docx file and tried to get the pagecount. It gave pagecount as 2 wherein the docx had only one page.

Can you please help to fix this issue?

I have a test class which returns the actual page count as 1. But I am facing issues through a web request (with user having browse button). I am also wondering how it is different.

Below is the piece of code I used to test. Same is used to validate the page count.

Document document = new Document(inputResourceAsStream);
System.out.println(" pagecount ######## = " + document.getPageCount());

Please let me know if you need any other information.

I tried with aspose.words 14.6.0 and 15.2.0.

Thanks,
Sivaraj.

Hi Sivaraj,

Thanks for your inquiry. I have tested the scenario using latest version of Aspose.Words for Java 15.3.0 and have not found the shared issue. Please use Aspose.Words for Java 15.3.0.

Thanks Tahir.

But, regardless of version, it always gives me a wrong count.

For the attached document in my first post on this thread, it always gives me count = 2.

I tried writing the outputstream to a docx to check whether there is something wrong. But, that also seemed to be fine.

Could you please help?

One more point to add is, we are not facing this problem with version 14.6.0.
I am not sure of changes got in to the latest version. Could you please let me know?

Thanks,
Sivaraj

Hi Sivaraj,

Thanks for your inquiry. Please call Document.updatePageLayout method to rebuild the page layout of the document and then use Document.PageCount property. Hope this helps you.

Document doc = new Document(MyDir + "Pro1+copy.docx");
doc.updatePageLayout();
System.out.println(doc.getPageCount());

If you still face problem, please share following detail for investigation purposes.

What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • Java version

Hi Tahir,

Thanks.

doc.updatePageLayout() did not help.

Below is the information.

java version “1.7.0_40”
Java™ SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot™ 64-Bit Server VM (build 24.0-b56, mixed mode)

OS X 10.9.2 (MacBook Pro)

Issue is same with linux too.

Hi Sivaraj,

Thanks for sharing the detail. I have tested the scenario at Ubuntu and have not found the shared issue. Please make sure that you are using the same document (which you attached in this forum thread) and using Aspose.Words for Java 15.3.0.

Moreover, I suggest you please copy all fonts from a Windows Machine to linux and then check the page count. Please read following documentation link for your kind reference.
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

Could you please convert your document to Pdf using following code example and share that Pdf here for our reference?

Document doc = new Document(MyDir + "input.docx"); 
doc.save(MyDir + "Out.pdf");

https://docs.aspose.com/words/java/specify-truetype-fonts-location/

Can someone respond to this issue? It is reproducible on 15.3.x…

Hi Sivaraj,

Thanks for your inquiry. Please check my previous post. We have not found this issue at our end.

*Moreover,
I suggest you please copy all fonts from a Windows Machine to linux and
then check the page count. Please read following documentation link for
your kind reference.
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

Could you please convert your document to Pdf using following code example and share that Pdf here for our reference?

Document doc = new Document(MyDir + “input.docx”);
doc.save(MyDir + “Out.pdf”);*