Count pages/lines in a word file that was edited w

2019-09-01 03:33发布

问题:

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