获取word段落所在页码
LayoutCollector lc = new LayoutCollector(doc);
使用他获取的段落所在页码 部署到服务器以后就不对了
这个怎么修改 还有没有其他方式
获取word段落所在页码
LayoutCollector lc = new LayoutCollector(doc);
使用他获取的段落所在页码 部署到服务器以后就不对了
这个怎么修改 还有没有其他方式
import org.apache.poi.xwpf.usermodel.*;
import java.io.FileInputStream;
import java.io.IOException;
public class WordPageNumber {
public static void main(String[] args) {
try {
// 加载Word文档
XWPFDocument document = new XWPFDocument(new FileInputStream("path/to/your/document.docx"));
// 获取所有段落
for (XWPFParagraph paragraph : document.getParagraphs()) {
// 获取段落所在的页码
int pageNumber = document.getPosOfParagraph(paragraph);
System.out.println("Paragraph: " + paragraph.getText() + ", Page Number: " + pageNumber);
}
// 关闭文档
document.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}