// Create a new workbook Workbook workbook = new Workbook(); IWorksheet sheet = workbook.getWorksheets().get(0); // Set text for some cells. sheet.getRange("A1").setValue("Document"); sheet.getRange("A2").setValue("Solutions For Java"); sheet.getRange("B1").setValue("Document"); sheet.getRange("B2").setValue("Solutions for Java"); //Set font size of cell "A2" sheet.getRange("A2").getFont().setSize(20); // Set bestFitColumns/bestFitRows as true. sheet.getPageSetup().setBestFitColumns(true); sheet.getPageSetup().setBestFitRows(true); // Set print gridline and heading. sheet.getPageSetup().setPrintGridlines(true); sheet.getPageSetup().setPrintHeadings(true); // Save to a pdf file workbook.save("ConfigureBestFitRowColumn.pdf");