使用aspose.words for java V24.3试用版,转换word文档的时候,1页的文档使用,wordDocument.getPageCount()返回2页,请问是什么原因,该怎么解决?
/**
* word文件获取页码和横板竖版
* @param
* @return
*/
public static Map<String,Object> getFileDetail(String filePath){
Document wordDocument = null;
InputStream inputStream = null;
try {
inputStream = new FileInputStream(filePath);
wordDocument = new Document(inputStream);
// 获取第一页的页面大小
PageSetup pageSetup = wordDocument.getFirstSection().getPageSetup();
double pageWidth = pageSetup.getPageWidth();
double pageHeight = pageSetup.getPageHeight();
Map<String,Object> map = new HashMap<>();
map.put("total",wordDocument.getPageCount());
if (pageWidth > pageHeight) {
map.put("iv","0");
} else {
map.put("iv","1");
}
return map;
} catch (Exception e) {
e.printStackTrace();
return null;
}finally {
// 在finally块中将Document对象设置为null释放资源
wordDocument = null;
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
1852165521999527936.docx (35.5 KB)