Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing worksheets and page size issue when excel (.xlsx) convert to pdf (.pdf) using open office

I have created an application using JodConverter and Open-Office for converting an excel(.xlsx) to PDF, The application works fine but i am facing two problems

  1. The pages of output PDF is in the form of A4 size, since because of that certain worksheet content have been sliced off. since i want each worksheet of the excel as complete as in one page what ever the size.

  2. The no of worksheets were missing, say if my excel has 8 worksheet i am getting only two or three within the PDF output

Even if we tried to convert to pdf directly from open-office, its giving the above similar issues

Excel File - ss1.xlsx

Output PDF - work.pdf

can anyone please tell me some solution for this

My code is as given below

public class MyConverter {

    public static void main(String[] args) throws ConnectException {
        File inputFile = new File("C:/Users/Work/Desktop/ss1.xlsx");
        File outputFile = new File("C:/Users/Work/Desktop/work.pdf");

        // connect to an OpenOffice.org instance running on port 8100
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
        connection.connect();

        // convert
        DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
        converter.convert(inputFile, outputFile);

        // close the connection
        connection.disconnect();
    }
like image 229
Alex Man Avatar asked Jun 17 '14 18:06

Alex Man


People also ask

Why is my Excel sheet so small when I convert to PDF?

Cause. The problem is that when a PostScript printer is selected as the default printer for Excel, the application does not scale the sheet size. This behavior is because with PostScript the output device does the scaling rather than Excel.


1 Answers

I used the (free) PrimoPDF printer driver to create the PDF directly from within Excel. The large number of pages (20+) is due to the fact that the 'fit to page' print option is missing in one of the worksheets, the 3rd if i remember well. After correcting this, the command to print all worksheets still results in 2 PDF files to be generated. PrimoPDF asks twice for a file name while it should ask only one. I assume your program just generates the PDF corresponding to the first part since normally only one PDF should be generated. I have no explanation for the 2-part printing. It might be due to some print setting in one of the worksheets that forces the printing to be performed in 'two batches'. For instance, a different resolution value may prevent printing in one batch. Conclusion: the workaround is to print with PrimoPDF and concatenate the 2 PDF files using one of the freely available programs on the web. For a durable solution you'll have to verify the print settings of all worksheets in detail and make sure they are equal.

like image 197
Paul1n Avatar answered Sep 27 '22 16:09

Paul1n