微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.artofsolving.jodconverter api 未在 wicket 8 应用程序中将 Excel 文件转换为 PDF 文件

如何解决org.artofsolving.jodconverter api 未在 wicket 8 应用程序中将 Excel 文件转换为 PDF 文件

我正在尝试使用以下这些 API 在 wicket 8 应用程序中将 excel 文件转换为 PDF 文件。但是 PDF 文件没有转换成 excel 文件,我在 PDF 下载链接上得到相同的 excel 文件而不是 PDF 文件,并且 convert() 方法没有异常或错误

<dependency>
    <groupId>net.sf.jodconverter</groupId>
    <artifactId>jodconverter</artifactId>
    <version>3.0-beta-4</version>
</dependency>

<dependency>
    <groupId>com.artofsolving</groupId>
    <artifactId>jodconverter</artifactId>
    <version>2.2.1</version>
</dependency>

使用下面的代码将excel文件转换为PDF文件

public File convertToPDFFile(ByteArrayOutputStream fromExcelFile,String sheetName,OOConfig ooConfig,FileFormat fileFormat) throws Exception {
    File tempFile = null;
    File resultPDFFile = null;
    try {
        tempFile = File.createTempFile(sheetName,fileFormat.getFileExtension());
        tempFile.setWritable(true);

        FileOutputStream fout = new FileOutputStream(tempFile);
        fromExcelFile.writeto(fout);

        ExternalOfficeManagerConfiguration eomcTest = new ExternalOfficeManagerConfiguration();
        eomcTest.setConnectOnStart(true);
        eomcTest.setConnectionProtocol("SOCKET");
        eomcTest.setPortNumber(8100);

        OfficeManager officeManager = eomcTest.buildOfficeManager();
        officeManager.start();
        OfficeDocumentConverter officeDocConverter = new OfficeDocumentConverter(officeManager);
        resultPDFFile = File.createTempFile(sheetName,TypeOfFile.PDF.getFileExtension());
        officeDocConverter.convert(tempFile,resultPDFFile);
        fout.close();
        officeManager.stop();
    } catch (Exception e) {
        e.printstacktrace();
    } finally {
        if (tempFile != null) {
            tempFile.delete();
            tempFile = null;
        }
    }
    return resultPDFFile;
}

请告诉我为什么 jodconverter 不将 excel 文件转换为 pdf 文件

任何建议都将受到高度赞赏。

解决方法

在本地系统中进行更深入的调试后,上面的代码对我有用。

为此需要安装 OpenOffice3 或版本 4,并且可以运行以下命令在 Windows 操作系统中将 OpenOffice 作为服务运行。

转到 CMD 并导航到 OpenOffice 程序目录路径: 示例:CMD 中的“C:\OpenOffice.org 3\program”和以下命令将 OpenOffice 作为服务运行以运行 Jodconverter 代码进行文件转换。

start soffice -headless -accept=socket,host=0,port=8100;urp;

这有助于在 Windows 操作系统的本地系统中将 OpenOffice 作为服务器运行,并且可以更深入地调试此代码以解决任何问题或进行任何更改。

我希望它可以帮助那些想要在本地系统中为您的 OpenOffice 应用程序执行此代码的人。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。