Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

java - org.artofsolving.jodconverter api not converting Excel file into PDF file in wicket 8 application

I am trying to convert excel file into PDF file in wicket 8 application by using these below APIs. But PDF file is not converting into excel file and I am getting that same excel file on the PDF download link instead of PDF file and there is no exception or error on convert() method.

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

or

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

Using this below code to convert excel file to PDF file

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

Kindly anyone let me know why jodconverter not converting excel file into pdf file.

Any suggestions will be highly appreciable.

question from:https://stackoverflow.com/questions/65942921/org-artofsolving-jodconverter-api-not-converting-excel-file-into-pdf-file-in-wic

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This above code worked for me after debugging deeper in the local system.

For that need to install OpenOffice3 or version 4 and can run below command to run the OpenOffice as a service in windows OS.

Go to CMD and navigate to OpenOffice program dir path: Example: "C:OpenOffice.org 3program" and below command in CMD to run the OpenOffice as a service to run the Jodconverter code for file conversion.

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

This can help to run the OpenOffice as a server in the local system for Windows OS and can debug this code in deeper to resolve any issue or to make any changes.

I hope it can help someone who wants to execute this code in the local system for your application with OpenOffice.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...