将DOCX转换为PDF [可能重复]

时间:2018-10-09 10:57:26

标签: java apache itext apache-poi

我已经搜索和测试代码整整一个星期了,尝试了许多库,还有更多其他事情。似乎Google和Stackoverflow上的当前答案已过时,原因是它们对apache poi和其他库所做的更新。

我一直试图将DOCX转换为带有图像的PDF,并保持与DOCX中显示的格式和布局相同。

我已经尝试过下面的代码,该代码来自here

    String inputFile="Test.docx";
    String outputFile="Tester.pdf";

    System.out.println("inputFile:" + inputFile + ",outputFile:"+ outputFile);
    FileInputStream in=new FileInputStream(inputFile);
    XWPFDocument document=new XWPFDocument(in);
    File outFile=new File(outputFile);
    OutputStream out=new FileOutputStream(outFile);
    PdfOptions options=null;
    PdfConverter.getInstance().convert(document,out,options);

我还使用以下库:

  

com.lowagie.text-.2.1.7.jar
  commons-codec-1.10.jar
  commons-collections4-4.2.jar
  commons-compress-1.18.jar
  curvesapi-1.04.jar
  fr.opensagres.xdocreport.itext.extension-2.0.1.jar
  org.apache.poi.xwpf.converter.core-1.0.6.jar
  org.apache.poi.xwpf.converter.pdf-1.0.6.jar
  poi-4.0.0.jar
  poi-ooxml-4.0.0.jar
  poi-ooxml-schemas-4.0.0.jar
  xmlbeans-3.0.1.jar

出现以下错误:

  

线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / poi / POIXMLDocumentPart
      在org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.getFontsDocument(XWPFStylesDocument.java:1477)
      在org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument。(XWPFStylesDocument.java:190)
      在org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument。(XWPFStylesDocument.java:184)
      在org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.createStylesDocument(XWPFDocumentVisitor.java:166)
      在org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor。(XWPFDocumentVisitor.java:159)
      在org.apache.poi.xwpf.converter.pdf.internal.PdfMapper。(PdfMapper.java:149)
      在org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
      在org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:38)       在org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
  引起原因:java.lang.ClassNotFoundException:org.apache.poi.POIXMLDocumentPart

要么我要解决这个问题,要么我看不到它。.否则,我不确定发生了什么。我研究了上述错误,并声称是Apache poi,不同版本试图相互通信,但是我已下载了所有最新的库。

0 个答案:

没有答案
相关问题