# Shrink To Fit With Text Wrap

DsExcel Java allows you to implement the shrink to fit feature in a cell along with the wrapped text.

## Content

DsExcel 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 :

* If you're exporting your Excel files to a pdf file or stream, the [PdfSaveOptions](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/PdfSaveOptions.html) class can be used to configure the save settings.
* In order to get or set the settings about enabling the shrink to fit feature on the wrapped text, you can use the the [getShrinkToFitSettings()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/PdfSaveOptions.html#getShrinkToFitSettings) method of the **PdfSaveOptions** class.
* The [getCanShrinkToFitWrappedText()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html#getCanShrinkToFitWrappedText) and [setCanShrinkToFitWrappedText()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html#setCanShrinkToFitWrappedText) methods of the [IShrinkToFitSettings](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html) interface can be used to get or set whether to apply the shrink to fit feature on the wrapped text. If the value is true, the font size of the wrapped text may be reduced so that the wrapped text can be fully displayed.
* The [getMinimumFont()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html#getMinimumFont) and the [setMinimumFont()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html#setMinimumFont) methods of the **IShrinkToFitSettings** interface can be used to get or set the minimum font size while enabling the shrink to fit feature.
* The [getEllipsis()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html#getEllipsis) and the [setEllipsis()](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IShrinkToFitSettings.html#setEllipsis) methods of the **IShrinkToFitSettings** interface can be used to get or set the omitted string if the wrapped text is not fully displayed. This can be used with the **getMinimumFont** and **setMinimumFont** methods.

## Using Code

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

```Java
// 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("Document Solutions 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);
```