如何在线程“main"中修复此异常java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship [英] How to fix this Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship

查看:201
本文介绍了如何在线程“main"中修复此异常java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公共类 CreatePdf {公共静态无效主(字符串 [] args){CreatePdf pdf = 新的 CreatePdf();System.out.println("开始");pdf.ConvertToPDF("D:\\doctopdf.docx", "D:\\Test1.pdf");}public void ConvertToPDF(String docPath, String pdfPath) {尝试 {InputStream doc = new FileInputStream(new File(docPath));XWPFDocument 文档 = 新 XWPFDocument(doc);PdfOptions 选项 = PdfOptions.create();OutputStream out = new FileOutputStream(new File(pdfPath));PdfConverter.getInstance().convert(document, out, options);System.out.print("完成");/*}catch(FileNotFoundException ex){System.out.print(ex.getMessage());*/}catch(IOException ex){System.out.print(ex.getMessage());}}}

<块引用>

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

解决方案

在标题上快速 google 给了我这个(仍然开放)问题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'

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

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());
        }
    }   
}

My requirement is to create a java code to convert existing docx into pdf with proper format and alignment.

解决方案

quick google on the title gave me this (still open) issue https://github.com/opensagres/xdocreport/issues/208

and the very last comment there says

khausam commented on 12 Mar I was using: compile group: 'fr.opensagres.xdocreport', name: 'org.apache.poi.xwpf.converter.xhtml', version: '1.0.6'

I switched to: compile group: 'fr.opensagres.xdocreport', name: 'fr.opensagres.poi.xwpf.converter.xhtml', version: '2.0.1'

And the problem was resolved. Can anyone confirm whether this is a reasonable and viable upgrade path?

这篇关于如何在线程“main"中修复此异常java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆