PDF generated through Aspose Cells has very small Font size

Actually, I need to convert an excel report (which has been generated in Aspose.Cells Java ) to Pdf format. The issue is that the text in the PDF file is very small making it unreadable. So, in my code, I tried to increase the font size but the font was still unreadable. Can you please suggest us some better way to convert excel files into pdf?

I am using the following piece of code:

public String convertToPdfFromExcelReport (String destinationPath, String SourcePath) {
try {
Workbook workbook = new Workbook(SourcePath);
Worksheet sheet = workbook.getWorksheets().get(0);
PageSetup pageSetup = sheet.getPageSetup();
Style style = sheet.getCells().getStyle();
Font font = style.getFont();
font.setName("Calibri");
font.setSize(14);
sheet.getCells().setStyle(style);
for(int rowIndex = 0 ; rowIndex < 106; rowIndex++){
if(rowIndex != 95 && rowIndex != 96 && rowIndex != 97 && rowIndex != 98){
sheet.getCells().setRowHeight(rowIndex, 14);
}else{
sheet.getCells().setRowHeight(rowIndex, 0);
}
}
pageSetup.setZoom(48);
pageSetup.setFitToPagesTall(1);
pageSetup.setCenterHorizontally(true);
PdfSaveOptions options = new PdfSaveOptions();
options.setPageIndex(0);
for (int i = 0; i <= workbook.getWorksheets().getCount(); i++) {
options.setPageCount(i);
}
options.setCompliance(PdfCompliance.NONE);
workbook.save(destinationPath, options);
return destinationPath;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Hi,

Thanks for your posting and using Aspose.Cells.

It appears to be font issue, as if required fonts are not installed on your system. Please check the attached screenshot, it shows the fonts used by the Pdf when MS-Excel 2016 generates it from your sample Excel file.

Please also check the Aspose.Cells generated Pdf with the following code and it is quite similar to MS-Excel generated Pdf.

So please install the fonts on your system or place them in some directory and set the font directory as shown in this document.


If your issue still occurs, then please provide us your expected Pdf, it should have comments that highlights your problem.

Please also download and try the latest version: Aspose.Cells for Java v17.3.10 and see if it makes any difference at your end.

Java

Workbook wb = new Workbook(dirPath + "GT-EV-Assesment-275-1492515112337.xlsx");
wb.save(dirPath + "cells-" + CellsHelper.getVersion() + ".pdf");

Hi,


Thanks for your posting and using Aspose.Cells.

We have looked into this issue further and found that the Zoom or Scale of your worksheet is set to 40%. Please set it to 100% either using MS-Excel or with Aspose.Cells.

Please see the attached screenshot for more help in this regard.

Please see the following sample code and read its comments. I have also attached the output pdf generated by the code as well as console output of the code for your reference.

Java

Workbook wb = new Workbook(dirPath + "GT-EV-Assesment-275-1492515112337.xlsx");

Worksheet ws = wb.getWorksheets().get("Ex F-EV Assessment-GT Method");

//Font size is small because this worksheet Zoom or Scale is 40%

System.out.println(ws.getPageSetup().getZoom());

//Please set the Zoom or Scale to 100% and it should fix your issue

ws.getPageSetup().setZoom(100);

wb.save(dirPath + "cells2-" + CellsHelper.getVersion() + ".pdf");

Console Output

40