Java turns Excel into PDF

This paper introduces how to convert an Excel workbook into a PDF document with a Java program, including

Tools used: Free Spire.XLS for Java (free version) https://www.e-iceblue.com/Introduce/free-xls-for-java.html

Getting and installing Jar files: Method 1: Download the jar file bag through the homepage. After downloading, unzip the file and install the Spire.xls.jar file under the lib folder into your Java program. https://www.e-iceblue.com/Download/xls-for-java-free.html

Method 2: Introduction by maven warehouse installation: https://www.e-iceblue.com/Tutorials/Licensing/How-to-install-Spire.PDF-for-Java-from-Maven-Repository.html

The Excel test document is as follows. Includes two sheets: Sample.png

JAVA Samples

Demo 1. Change the entire workbook to PDF


import com.spire.xls.*;

public class ExcelToPDF {
    public static void main(String[] args) {
        //Import an Excel document
        Workbook wb = new Workbook();
        wb.loadFromFile("test.xlsx");

        //Save the calling method in PDF format
        wb.saveToFile("ToPDF.pdf",FileFormat.PDF);
    }
}

Effect diagram:

Excel to PDF 1.png

Demo 2. Change the specified sheet to PDF


import com.spire.xls.*;

public class ExcelToPDF {
    public static void main(String[] args) {
        //Import an Excel document
        Workbook wb = new Workbook();
        wb.loadFromFile("test.xlsx");

        //Get the second sheet
        Worksheet sheet = wb.getWorksheets().get(1);

        //Save the calling method in PDF format
        sheet.saveToPdf("ToPDF2.pdf");
    }
}

Effect diagram: Excel to PDF 2.png

The END

Recommended Posts

Java turns Excel into PDF
Save Java PDF in Excel
[Java] Convert PDF version
Java compressed PDF document
Print Java Excel Worksheet
[Java] PDF viewing settings
Java merge & unmerge Excel cell
Java encryption and decryption PDF
Let's operate Excel with Java! !!
Importing Excel data in Java 2
Paging PDF with Java + PDFBox.jar
Save Java HTML as PDF
Import Excel data in Java
Java addition excel data validation
Java creates an Excel document
Importing Excel data in Java 3
Java sets Excel document properties
Java Excel Insertion and Image Extraction
I created a PDF in Java.
Java to extract PDF text content
Add, modify, delete JAVA PDF bookmarks
Output PDF and TIFF with Java 8
Add, replace, delete Java PDF images
Add watermark to Java to PDF document
EXCEL file update sample with JAVA
Java draws shapes in PDF documents
Java adds form fields to PDF
Java adds and reads Excel formulas