【问题标题】:get the number of pages in a word document using aspose使用 aspose 获取 word 文档的页数
【发布时间】:2014-03-19 08:18:51
【问题描述】:

如何使用 Aspose java 获取 word 文档(.doc 或 .docx)中的页数? 或者可能在不使用 Aspose 的情况下在 java 中获取 word 文档中的页数。

【问题讨论】:

    标签: java aspose.words


    【解决方案1】:

    您可以使用 Document.getPageCount 方法在 Aspose.Words for Java 中获取 doc / docx 文件的页数。以下是示例代码:

    //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);
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      要从流中打开,只需将包含文档的流对象传递给 Document 构造函数。下面的代码示例展示了如何从流中打开文档并获取页数。

      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();
      

      我与 Aspose 合作,担任开发人员宣传员。

      【讨论】:

      • 与其他答案中的方法相比,在您的示例中使用 FileInputStream 是否有优势?
      • @Mike Brockington,不,没有任何区别。 Aspose.Words 在两种情况下都会返回相同的页数。
      猜你喜欢
      • 2013-05-29
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多