【问题标题】:How to fix this Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship如何在线程“main”java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship 中修复此异常
【发布时间】:2018-05-24 06:16:01
【问题描述】:
public class CreatePdf {

    public static void main(String[] args) {
        CreatePdf pdf = new CreatePdf();
        System.out.println("start");
        pdf.ConvertToPDF("D:\\doctopdf.docx", "D:\\Test1.pdf");
    }

    public void ConvertToPDF(String docPath, String pdfPath) {

        try {
            InputStream doc = new FileInputStream(new File(docPath));
            XWPFDocument document = new XWPFDocument(doc);
            PdfOptions options = PdfOptions.create();
            OutputStream out = new FileOutputStream(new File(pdfPath));
            PdfConverter.getInstance().convert(document, out, options);
            System.out.print("Done");
      /*}catch(FileNotFoundException ex){
            System.out.print(ex.getMessage());*/
        }catch(IOException ex){
            System.out.print(ex.getMessage());
        }
    }   
}

我的要求是创建一个 java 代码,将现有的 docx 转换为具有正确格式和对齐方式的 pdf。

【问题讨论】:

  • 你在哪里调用那个方法?
  • @XtremeBaumer,显然这是从库代码中抛出的

标签: java pdf apache-poi


【解决方案1】:

标题上的快速谷歌给了我这个(仍然开放的)问题 https://github.com/opensagres/xdocreport/issues/208

最后一条评论说

khausam 在 3 月 12 日评论我正在使用:编译组: 'fr.opensagres.xdocreport',名称: 'org.apache.poi.xwpf.converter.xhtml',版本:'1.0.6'

我切换到:编译组:'fr.opensagres.xdocreport',名称: 'fr.opensagres.poi.xwpf.converter.xhtml',版本:'2.0.1'

问题就解决了。谁能确认这是否是 合理可行的升级路径?

【讨论】:

  • 我将 poi 库的版本从 poi 3.17 更改为 poi 3.15。问题就解决了。
猜你喜欢
  • 1970-01-01
  • 2017-09-24
  • 1970-01-01
  • 2011-01-14
  • 1970-01-01
  • 2011-02-20
  • 1970-01-01
  • 2016-01-05
  • 2021-02-10
相关资源
最近更新 更多