问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/22499907/get-the-number-of-pages-in-a-word-document-using-aspose