你好,现在有一个获取表格页码与word文档中的问题,在word中表格处于第2页。但是用aspose读取时,显示是3页。
(1)代码如下:
import com.aspose.words.Document;
import com.aspose.words.LayoutCollector;
import com.aspose.words.NodeCollection;
import com.aspose.words.NodeType;
import com.aspose.words.Table;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
public class MyAspose {
public static void main(String[] args) {
testPageNumber();
}
public static void testPageNumber() {
String filePath = "D:\\aspose问题\\";
String fileName = "页码1.docx";
File file = new File(filePath + fileName);
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
Document doc = new Document(inputStream);
LayoutCollector layoutCollector = new LayoutCollector(doc);
NodeCollection<Table> tables = doc.getChildNodes(NodeType.TABLE, true);
for (Table table : tables) {
String pageNumber = "";
int index = layoutCollector.getStartPageIndex(table);
if (index > 0) {
pageNumber = String.valueOf(index);
}
System.out.println("pageNumber: " + pageNumber);
}
} catch (Exception e) {
System.out.println("Exception:" + e);
}
}
}
(2)word中的表格所在页码如下:
(3)测试文档如下:
页码1.docx (37.1 KB)
请给予协助,不胜感激!