Documents for Excel, Java Edition Documentation
Manage File Operations / Export to a PDF File / Shrink To Fit With Text Wrap
In This Topic
    Shrink To Fit With Text Wrap
    In This Topic

    GcExcel Java allows users to apply the shrink to fit feature in a cell along with the wrapped text. This feature reduces the font size of the text automatically so that it fits inside the cells of the spreadsheet without wrapping. 

    Advantage of Using Shrink To Fit Feature

    The Shrink to Fit feature implemented with wrapped text is useful especially when you need to deal with spreadsheets possessing tightly constrained layouts with vertical spaces and wrapped text. Also, this feature can be used when users don't want to opt for Auto fit row height and column width option to adjust the column width and row height as per their preferred worksheet layout.

    The following points should be kept in mind while working with the shrink to fit feature :

    Using Code

    Refer to the following example code in order to allow users to use the shrink to fit feature with text wrap.

    Java
    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
            
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    worksheet.getPageSetup().setPrintGridlines(true);
    worksheet.getRange("A1").setRowHeightInPixel(20);
    worksheet.getRange("A1").setColumnWidthInPixel(90);
    worksheet.getRange("A1").setWrapText(true);
    worksheet.getRange("A1").setShrinkToFit(true);
    worksheet.getRange("A1").setValue("GrapeCity Documents For Excel");
    
    // Setting PdfSaveOptions
    PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
    pdfSaveOptions.getShrinkToFitSettings().setCanShrinkToFitWrappedText(true);
    pdfSaveOptions.getShrinkToFitSettings().setMinimumFont(10);
    pdfSaveOptions.getShrinkToFitSettings().setEllipsis("~");
    
    // Saving the workbook to pdf
    workbook.save("ShrinkToFitWrappedText.pdf", pdfSaveOptions);