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

Free Support Forum - aspose.com

Page count issue for .DOCX (msword) file


We are having the page count issue with .docx file using Aspose.Words for Java product. I got the temporary license and downloaded Aspose.Words for Java 11.6.0 (latest version of product) to count the number of pages of .docx word document.

We are getting a byte array as a word document, dynamically created, by third party. Please find the attached .docx file for which I would like to count the total number of pages.

I am using folowing code to count the number of pages and I hope there would not be any issue with this code

public class TestWordDocUtil {

public static void main(String[] args) {

try {

// Load the ASPOSE license (load this at only once).

try {

com.aspose.words.License license = new com.aspose.words.License();

byte[] licByte = SBCMgmtUtil.getPayload("Aspose.Words.lic");

ByteArrayInputStream licInputStream = new ByteArrayInputStream(licByte);


System.out.println("ASPOSE licence successfully loaded.");


catch (Exception e) {

System.out.println("Exception while loading ASPOSE licence. " + e);


int noPages = 0;

ByteArrayInputStream docxInputStream = new ByteArrayInputStream(createByteArrayWordDoc());

Document wordDoc = new Document(docxInputStream);

noPages = wordDoc.getPageCount();

System.out.println("Number of pages in word document using ASPOSE " + noPages);


catch(Exception eEx) {




public static byte[] createByteArrayWordDoc() {

String path = "C:" + File.separator + "example" + File.separator + "Sample_Test.docx";

byte inputBytePDF[] = null;

try {

//create file object

File file = new File(path);

//create FileInputStream object

FileInputStream fin = new FileInputStream(file);

inputBytePDF = new byte[(int)file.length()];



catch (FileNotFoundException e) {

System.out.println("FileNotFoundException " + e);


catch (IOException ioe) {

System.out.println("IOException " + ioe);


catch (Exception e) {

System.out.println("Exception " + e);


return inputBytePDF;



As per my analysis there is something wrong with the attached .docx file format. If I do some change in attached word file and save the document using MS Office then I am getting the correct page count with updated file using ASPOSE Word API.

Aspose.Words supports DOC, OOXML, RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats. I am assuming .docx is the Office Open XML standards (OOXML), but I don't see the 9 element in extracted app.xml file of attched docx file. As per my understanding to count the pages of the .docx file, the file should be OOXML format.

Please help us to resolve this issue and correct me if my assumptions and / or understanding is wrong. Just recently we purchased ASPOSE PDF kit and now would like to use ASPOSE Word product.

Thanks, Avinash

Hi Avinash,

Thanks for your query. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-6809 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-6809) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.