使用apache-POI将word文档转换为pdf时出错

时间:2016-08-23 07:52:00

标签: apache-poi

我正在尝试使用apache-POI将word文档转换为pdf,但我得到了一个例外:

java.lang.NoSuchMethodError:org.apache.poi.util.POILogger.log(I[Ljava/lang/Object;)V

这是我的代码:

InputStream is = new FileInputStream(new File("D:\\2161-1041-5-157.docx"));
XWPFDocument document = new XWPFDocument(is);

// 2) Prepare Pdf options
PdfOptions options = PdfOptions.create();

// 3) Convert XWPFDocument to Pdf
OutputStream out = new FileOutputStream(new File("D:\\2161-1041-5-157.pdf"));
PdfConverter.getInstance().convert(document, out, options);

完整的异常和callstack是:

  

java.lang.NoSuchMethodError:
  org.apache.poi.util.POILogger.log(I [Ljava / lang / Object;)V at

  org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:314)
    在
  org.apache.poi.openxml4j.opc.PackageRelationshipCollection。(PackageRelationshipCollection.java:164)
    在
  org.apache.poi.openxml4j.opc.PackageRelationshipCollection。(PackageRelationshipCollection.java:132)
    在
  org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:561)
    在
  org.apache.poi.openxml4j.opc.PackagePart。(PackagePart.java:109)
    在
  org.apache.poi.openxml4j.opc.PackagePart。(PackagePart.java:80)
    在
  org.apache.poi.openxml4j.opc.PackagePart。(PackagePart.java:125)
    在
  org.apache.poi.openxml4j.opc.ZipPackagePart。(ZipPackagePart.java:78)
    在
  org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:237)
    在
  org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:696)
    在org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:280)
    在org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)上   org.apache.poi.xwpf.usermodel.XWPFDocument。(XWPFDocument.java:128)
    在org.open.word.POIWordToPDF.createPDF(POIWordToPDF.java:27)上   org.open.word.POIWordToPDF.main(POIWordToPDF.java:18)

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.14</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.11</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>3.14</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-scratchpad</artifactId>
    <version>3.14</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>ooxml-schemas</artifactId>
    <version>1.3</version>
</dependency>

0 个答案:

没有答案