Count pages/lines in a word file that was edited with docx4j

喜欢而已 提交于 2020-01-06 04:45:05

问题


I found some posts here how to count pages/lines with the apache-poi library. But my code already uses docx4j right now, it would be too much work to completely replace that.

Therefore my question is, how can I get from an object of type WordprocessingMLPackage to an object of type XWPFDocument in order to count the lines and pages of my current document.

private XWPFDocument convertDocx4J(WordprocessingMLPackage wp) {
    XWPFDocument oiDoc = null;

    //TODO...

    return oiDoc;
}

回答1:


Easiest way to go from docx4j's WordprocessingMLPackage to POI would be to use docx4j's API to save as docx, then POI's to load.

But you can get page info from docx4j; see https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/toc/TocGenerator.java#L657



来源:https://stackoverflow.com/questions/49176920/count-pages-lines-in-a-word-file-that-was-edited-with-docx4j

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