get the number of pages in a word document using aspose

ε祈祈猫儿з 提交于 2019-12-11 10:07:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!