Convert Excel to PDF issue with documents4j

0 votes

I want to use documents4j to convert Excel files to PDF but there are two issues:

  1. I must open an Excel file when converting. When I convert Word to PDF, I didn't need open a doc/docx file.
  2. The PDFs are not containing a chart image that is contained in Excel.

How can I resolve this? Here is code that reproduces the issue:

private void convertExcelToPDF1() throws Exception {

    InputStream excelFileIS = new BufferedInputStream(new FileInputStream("C:\\test_convert\\test.xlsx"));
    File target = new File("C:\\test_convert\\sim_status_excel.pdf");

    IConverter converter = RemoteConverter.builder()
                       .baseFolder(new File("D:\\temp"))
                       .workerPool(20, 25, 2, TimeUnit.SECONDS)
                       .requestTimeout(10, TimeUnit.SECONDS)
                       .baseUri("http://localhost:9998")
                       .build();

    Future<Boolean> conversion = converter.convert(excelFileIS).as(DocumentType.XLSX)
                                    .to(target).as(DocumentType.PDF)
                                    .prioritizeWith(1000)
                                    .schedule();
}
Sep 25 in Others by Kithuzzz
• 20,660 points
198 views

1 answer to this question.

0 votes

MS Excel may not always be used for programmatic conversion. As a result, odd problems can arise. First things first: Have you tried directly using MS Excel to convert your file to PDF? If the problems exist there as well, documents4j is helpless.

Other than that, there might be a report-options set that is required for making the export successful. You can have a look at the VBS scripts that documents4j runs for triggering Excel conversion: https://github.com/documents4j/documents4j/tree/master/documents4j-transformer-msoffice/documents4j-transformer-msoffice-excel/src/main/resources.

These files can be opened locally and run. You must first launch excel start.VBS from the Windows command prompt. Then you execute excel convert.VBS input.xls output.pdf 999, which causes the specified file to be converted to PDF. After finishing, you can tidy up by running excel stop.VBS.

The two parameters that are interesting to you are:

excelApplication.Workbooks.Open(inputFile, , True, , , , , , , , , , , , 2)

And

excelDocument.ExportAsFixedFormat xlTypePDF, outputFile
answered Sep 26 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
0 answers

Convert Rows to Columns with values in Excel using custom format

1 I having a Excel sheet with 1 ...READ MORE

Feb 17 in Others by Edureka
• 13,640 points
112 views
0 votes
1 answer

Convert Excel and Word files to PDF Using ruby

 You can combine some: For excel files - ...READ MORE

answered Sep 26 in Others by narikkadan
• 37,660 points
145 views
0 votes
1 answer

Convert csv- or Excel-file (xlsx) to kml with custom markers

With some help from the community, I ...READ MORE

answered Sep 26 in Others by narikkadan
• 37,660 points
110 views
0 votes
1 answer

Codeigniter convert excel file to pdf

This is a basic php script for ...READ MORE

answered Sep 27 in Others by narikkadan
• 37,660 points
187 views
0 votes
1 answer

Java Spring - Writing Excel file and converting to PDF

Since you are using Spring I suggest ...READ MORE

answered Sep 26 in Others by narikkadan
• 37,660 points
272 views
0 votes
1 answer

Using Java to create PDF graphs based on Excel formulas

The Apache POI project, an API for ...READ MORE

answered Oct 22 in Others by narikkadan
• 37,660 points
82 views
0 votes
1 answer

How can I convert a Word document to PDF?

This is a difficult task, made even ...READ MORE

answered Oct 31 in Others by narikkadan
• 37,660 points
63 views
0 votes
0 answers

how to send a pdf file as a response to frontend?

when a user upload a file to ...READ MORE

Apr 11, 2020 in Java by Abhishek
• 120 points
2,126 views
0 votes
1 answer

Convert Word doc, docx and Excel xls, xlsx to PDF with PHP

After receiving a request, I'll put the ...READ MORE

answered Nov 20 in Others by narikkadan
• 37,660 points
64 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24 in Others by narikkadan
• 37,660 points
131 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP