Documents for Excel, Java Edition Documentation
File Operations / Export to PDF / Configure Fonts and Set Style
In This Topic
    Configure Fonts and Set Style
    In This Topic

    GcExcel Java enables users to configure custom fonts and set styles while saving worksheets in PDF format.

    Before executing the export operation, users need to make sure they specify the font path that should be used while saving the PDF. If the folder path to the font is not specified and the user is working on Windows OS, the path "C:\Windows\Fonts" will be used by default. However, if the folder path to the font is not specified and the user is working on any other operating system, it is necessary that the user sets the font folder path and copies the used font files to the folder "C:\Windows\Fonts".

    The getUsedFonts() method of the IWorkbook interface can be used to get the collection of all the fonts used in the workbook.

    While exporting to a PDF file, GcExcel Java uses the fonts specified in the Workbook.FontsFolderPath in order to render the PDF. However, if the used font doesn't exist, it will make use of some fallback fonts. In case, fallback fonts don't exist in the file, GcExcel Java will throw the exception :"There are no available fonts. Please set a valid path to the FontsFolderPath method of the Workbook!"

    In order to configure fonts and set style while saving to a PDF, refer to the following example code.

    Copy Code
    // Create a new workbook and add worksheets
    Workbook workbook = new Workbook();
    IWorksheet sheet1 = workbook.getWorksheets().get(0);
    IWorksheet sheet2 = workbook.getWorksheets().add();
    // Set style.
    sheet1.getRange("A1").getFont().setName("Wide Latin");
    // Add Table
    ITable table = sheet1.getTables().add(sheet1.getRange("C1:E5"), true);
    // Specify font path
    Workbook.FontsFolderPath = "C:\\Users\\GPCTAdmin\\Documents\\Fonts";
    // Get the used fonts list in workbook, the list are:"Wide Latin", "Calibri"
    List<FontInfo> fonts = workbook.getUsedFonts();
    // Save to a pdf file"configureFontsAndSetStyle.pdf", SaveFileFormat.Pdf);
    // Just export sheet1 to pdf file."configureFontsAndSetStyle_sheet.pdf",SaveFileFormat.Pdf);

    Note: The Export to PDF feature in GcExcel Java doesn't support saving the following worksheet styles to PDF format:

    a) Usage of double underline, single acounting underline, double accounting underline, superscript font effect, subscript font effect.

    b) Alignment Preferences like center across selection, fill alignment, justify alignment, distributed alignment, orientation and text reading order etc.