Documents for Excel, Java Edition Documentation
Manage File Operations / Export to a PDF File
In This Topic
    Export to a PDF File
    In This Topic

    GcExcel Java enables users to save all visible spreadsheets in a workbook to a Portable Document File (PDF) using the save() method of the IWorkbook interface. Each worksheet in a workbook is saved to a new page in the PDF file. However, if users want to export only the current sheet (active sheet) to PDF format, they can use the save() method of the IWorksheet interface.

    The handling of images in the case of PDF export is also very efficient. If a picture is used multiple times in a spreadsheet, GcExcel maintains a single copy of the picture which reduces the size of exported PDF file.

    In order to export a spreadsheet to a PDF file, refer to the following example code.

    Java
    Copy Code
    // Create a new workbook and add worksheets
    Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    IWorksheet worksheet1 = workbook.getWorksheets().add();
            
    // Set value and apply styles to the worksheet
    worksheet1.getRange("A1").setValue("Sheet1");
    worksheet1.getRange("A1").getFont().setName("Wide Latin");
    worksheet1.getRange("A1").getFont().setColor(Color.GetRed());
    worksheet1.getRange("A1").getInterior().setColor(Color.GetGreen());
            
    // Export Workbook to pdf file, the exported file has two pages.
    workbook.save("ConvertWorkbookToPDF.pdf", SaveFileFormat.Pdf);
           
    // Just export a particular worksheet to pdf file
    worksheet1.save("ConvertWorksheetToPDF.pdf", SaveFileFormat.Pdf)

    While executing the export operation, you can configure fonts, set style and specify the page setup options in order to customize the PDF as per your preferences. Refer to the following topics for more details:

    Note: The Export to PDF feature in GcExcel Java doesn't support charts and slicers while saving a spreadsheet into PDF format. Besides this, exporting picture settings (such as LineFormat, FillFormat, Brightness, Contrast, Watermark Color Type and black and white pictures in emf format) to PDF are also not supported.