//create to a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("ShrinkToFitForWrappedText.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } //create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getPageSetup().setPrintGridlines(true); worksheet.getPageSetup().setPrintHeadings(true); //"A1" is ordinary wrapped text. worksheet.getRange("A1").setWrapText(true); worksheet.getRange("A1").setValue("GrapeCity Documents for Excel"); worksheet.getRange("A1").setRowHeight(38); worksheet.getRange("A1").setColumnWidth(9); //The wrapped text "A2" will be shrink to fit. //worksheet.Range["A2"].Interior.Color = Color.LightGreen; worksheet.getRange("A2").setWrapText(true); worksheet.getRange("A2").setShrinkToFit(true); worksheet.getRange("A2").setValue("GrapeCity Documents for Excel"); worksheet.getRange("A2").setRowHeight(38); //You must create a pdfSaveOptions object before using ShrinkToFitSettings. PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //Shrink the wrapped text within the cell with existing row height/column width, while exporting to PDF. pdfSaveOptions.getShrinkToFitSettings().setCanShrinkToFitWrappedText(true); ////Set minimum font size with which the text should shrink. //pdfSaveOptions.getShrinkToFitSettings().setMinimumFont(10); ////If after setting the minimum font size, the text is very long not fully visible, the ellipsis string to show for long text. //pdfSaveOptions.getShrinkToFitSettings().setEllipsis("~"); //Save the workbook into pdf file. workbook.save(outputStream, pdfSaveOptions); //close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
//create to a pdf file stream var outputStream: FileOutputStream? = null try { outputStream = FileOutputStream("ShrinkToFitForWrappedText.pdf") } catch (e: FileNotFoundException) { e.printStackTrace() } //create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) worksheet.pageSetup.printGridlines = true worksheet.pageSetup.printHeadings = true //"A1" is ordinary wrapped text. worksheet.getRange("A1").wrapText = true worksheet.getRange("A1").value = "GrapeCity Documents for Excel" worksheet.getRange("A1").rowHeight = 38.0 worksheet.getRange("A1").columnWidth = 9.0 //The wrapped text "A2" will be shrink to fit. //worksheet.Range["A2"].Interior.Color = Color.LightGreen; worksheet.getRange("A2").wrapText = true worksheet.getRange("A2").shrinkToFit = true worksheet.getRange("A2").value = "GrapeCity Documents for Excel" worksheet.getRange("A2").rowHeight = 38.0 //You must create a pdfSaveOptions object before using ShrinkToFitSettings. val pdfSaveOptions = PdfSaveOptions() //Shrink the wrapped text within the cell with existing row height/column width, while exporting to PDF. pdfSaveOptions.shrinkToFitSettings.canShrinkToFitWrappedText = true ////Set minimum font size with which the text should shrink. //pdfSaveOptions.getShrinkToFitSettings().setMinimumFont(10); ////If after setting the minimum font size, the text is very long not fully visible, the ellipsis string to show for long text. //pdfSaveOptions.getShrinkToFitSettings().setEllipsis("~"); //Save the workbook into pdf file. workbook.save(outputStream, pdfSaveOptions) //close the file stream try { if(outputStream != null){ outputStream.close() } } catch (e: IOException) { e.printStackTrace() }