使用 java 阅读 docx 文档

read docx document using java

我有一个隐写术项目,可以将 docx 文档隐藏到 jpeg 图像中。使用 apache POI,我可以 运行 它并阅读 docx 文档,但只能阅读字母。

虽然里面有图片。

这是代码

FileInputStream in = null;
    try
    {
        in = new FileInputStream(directory);
        XWPFDocument datax = new XWPFDocument(in);
        XWPFWordExtractor extract = new XWPFWordExtractor(datax);
        String DataFinal = extract.getText();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        this.isi_file = extract.getText();
    }
    catch (IOException x) {}
        System.out.println("isi :" + this.isi_file);

如何使用 java 读取 docx 文档中的所有组件?请帮助我,谢谢你的帮助。

请检查 documentation XWPFDocument class。它包含一些有用的方法,例如:

您的代码片段中存在第 XWPFDocument datax = new XWPFDocument(in); 行。所以在那一行之后你可以写一些代码,比如:

// process all pictures in document
for (XWPFPictureData picture : datax.getAllPictures()) {
    // get each picture as byte array
    byte[] pictureData = picture.getData();
    // process picture somehow
    ...
}