Java – when excel (. Xlsx) is converted to PDF (. PDF) using open office, there are missing worksheets and page size problems
I have created an application using jodconverter and open office to convert excel (. Xlsx) to PDF. The application works normally, but I face two problems
>The output PDF page is in A4 size because some worksheet contents have been cut off Because I want every worksheet in Excel to be as complete as a page. > No worksheets are missing. If my excel has 8 worksheets, I only have two or three in the PDF output
Even if we try to convert directly from open office to PDF, we also give the above similar problems
Excel file – SS1 xlsx
Output PDF – work pdf
Anyone can tell me some solutions
My code is as follows
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(); }
Solution
I use the (free) primo pdf printer driver to create PDF directly in Excel The large number of pages (20) is due to the fact that the "fit page" printing option is missing in one of the worksheets, if I remember, page 3 After correcting this, the command to print all worksheets will still result in 2 PDF files Primopdf requires two file names, and it should only ask for one I assume that your program generates only the PDF corresponding to the first part, because usually only one PDF can be generated I didn't explain the printing of Part 2 This may be due to some print settings in one of the worksheets that force printing to be performed in "two batches" For example, different resolution values may prevent a print Conclusion: the solution is to print with primo PDF and connect two PDF files using one of the free programs on the network For a durable solution, you must verify the print settings of all worksheets in detail and ensure that they are the same