0

我正在尝试使用 xdocreport 将 docx 转换为 pdf,但最终我发现 IRunBody 类的 classnot found 异常。我的包 'org.apache.poi.xwpf.usermodel' 似乎没有这个接口。我有所有需要的罐子。poi,poi-ooxml,poi-ooxml-schemas,但我无法获得这个类。谁能让我知道我在这里想念什么?我需要添加任何其他罐子吗?下面是我正在运行的代码

        XWPFDocument xwpfDoc = new XWPFDocument(new FileInputStream(fileName));
        PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
        String randomFilename = UUID.randomUUID().toString();
        String outputFIlePath = TEMPORARY_PDF_FILE_LOCATION + randomFilename + ".pdf";
        OutputStream output = new FileOutputStream(outputFIlePath);
        PdfConverter.getInstance().convert(xwpfDoc, output, options);
4

2 回答 2

1

我的 ooxml jar 不是最新的。更新ooxml jar后,问题得到解决。谢谢你。

于 2015-08-10T17:56:38.260 回答
0

我有完全相同的问题。我解决了它!

因为我的项目不是 Maven,所以我不能使用好的 Dependencies maven 解析器 - 我所做的是 1) 只是临时创建了新的空 Maven 项目;2)在 pom.xml 中,我只添加了我需要的库所需的这 3 个:

  <dependencies>
    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>org.apache.poi.xwpf.converter.core</artifactId>
        <version>1.0.5</version>
    </dependency>

    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
        <version>1.0.5</version>
    </dependency>

    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>
        <version>1.0.5</version>
    </dependency>

  </dependencies> 

3) 更新了这个 Maven 项目,所以它下载了所有这些库及其所有依赖项,所以我得到了这个jars

在此处输入图像描述4)然后只需将这些罐子 复制到我的真实项目中就可以了!

我建议您做同样的事情,而不是尝试手动解决依赖关系。

于 2016-06-30T18:22:16.830 回答