Question

how can i get the number of pages in a word document(.doc or .docx) using Aspose java? or maybe get the number of pages in a word document in java without using Aspose.

Était-ce utile?

La solution

You can use Document.getPageCount method to get the page count of a doc / docx file in Aspose.Words for Java. Following is the sample code:

//Open the Word Document                                 
Document doc = new Document("C:\\Data\\Image2.doc");     

//Get page count                                         
int pageCount = doc.getPageCount();

//Print Page Count            
System.out.println(pageCount);

Hope this helps.

Autres conseils

To open from a stream simply pass a stream object that contains a document to the Document constructor. The code sample below shows how to open a document from a stream and get number of Pages.

String dataDir = "D:\\Temp\\";
String filename = "input.docx";

InputStream in = new FileInputStream(dataDir + filename);

Document doc = new Document(in);
System.out.println("Document opened. Total pages are " + doc.getPageCount());
in.close();

I work with Aspose as Developer Evangelist.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top