Arial font not picked up in PDF when Excel is converted to PDF in Java

Hi,


My requirement is to generate an Excel and a PDF in Arial 8 font.

I am generating the Excel using ASPOSE.Cells and then converting it into PDF using the following code:
//Instantiate a new workbook with excel file path
Workbook workbook = new Workbook(“F:\FileTemp\Book1.xls”);
//Save the document in Pdf format
workbook.save(“F:\FileTemp\MyPdfFile.pdf”, FileFormatType.PDF);
When I generate the Excel normally using XLSX as the FileFormatType then the font of the text appears correctly(Arial 8 - Please see attachment 1)

However, when I generate the PDF, the font changes to LucidaSans.(Please see attachment 2)
The document has to be generated in Arial 8 font.

Need help on why this is happening. Upon investigating the issue a bit, we found that the font Arial was not installed on the server. We have uploaded the font as well on the server now but despite that, we are still facing this issue. (Please see attachment 3)

Any help/support would be greatly appreciated.

Hi Robert,

Thank you for contacting Aspose support.

First of all, please note that Aspose.Cells APIs need the required fonts (used in spreadsheet) to be present on the same machine where conversion is taking place. In case the required fonts are not present, the API will try to substitute the font with the ones available. Same is happening in this case. In order to avoid the said problem, please place the required font files (TTFs of Arial font family) in any folder of your server and explicitly tell the API where you have placed the fonts while using the FontConfigs.setFontFolder method if you are using latest release 8.9.1 or CellsHelper.setFontDir if you are using any release other than the latest one. Please be advised that font setting statements should be at the top of your application, that is; before invoking any other objects from Aspose.Cells APIs.

Please check the article Dealing with Font Settings on this subject.

Hi,


As suggested by you all the required font files are installed on the server and the server font folder path is being referred through CellsHelper.setFontDir() function. PFA code snippet for reference.

Attached is the list of font files installed on the server.As you can see along with Arial font other fonts such as Times New Roman,MS-Gothic,SimSun are also installed on the server.

When the excel file is being converted to PDF all the other fonts installed on the server are getting embedded in the PDF file except for Arial Font.If we try to include Arial font in the PDF the text with Arial font automatically converts to SimSun and the same gets embedded into the PDF.

Any help/support that could shed some light on the issue would be greatly appreciated.

Hi Robert,


Thank you for writing back.

I have noticed a problem with your code snippet. Please note, CellsHelper.setFontDir is static method which should be invoked without the need for creating an instance of a class. Please use the aforementioned method as follow. Moreover, the statement should be at the top of your application, that is; before creating any other instance of Aspose.Cells APIs.

In case the problem persists, please share more details of your environment (operating system, JDK & Aspose.Cells API versions) as well as sample spreadsheet along with its PDF for our review.

Java


CellsHelper.setFontDir(path to font files);

Hi again,

Could you please perform the following test with & without setting the font directory, and share the resultant files here? Please also share the TTFs of Arial font family available in your Linux environment.

Java

Workbook book = new Workbook();
Style style = book.createStyle();
style.getFont().setName(“Arial”);
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
cells.get(“A1”).putValue(“Arial Regular”);
cells.get(“A1”).setStyle(style);
cells.get(“A2”).putValue(“Arial Italic”);
style.getFont().setItalic(true);
cells.get(“A2”).setStyle(style);
cells.get(“A3”).putValue(“Arial Bold & Italic”);
style.getFont().setBold(true);
cells.get(“A3”).setStyle(style);
cells.get(“A4”).putValue(“Arial Bold”);
style.getFont().setItalic(false);
cells.get(“A4”).setStyle(style);
book.save(dir + “output.xlsx”);
book.save(dir + “output.pdf”);

Hi,


We have done what you asked for. PFA the resultant PDF and Excel files.

We are in the process of acquiring the TTF files for Arial Font.

The problem still persists for Arial font.

Please share your thoughts.

Hi Robert,


I have checked your provided samples and I have noticed that the PDF was not generated with Aspose.Cells for Java APIs. Please check the attached snapshot and clarify how you are producing the PDF.

Hi,


We were trying something else hence shared a wrong file.

This is the actual file that should have been shared.


Hi Robert,


Thank you for sharing the PDF generated with Aspose.Cells for Java. We will require your TTF files for the Arial font family to initiate an investigation in this regard. Moreover, please confirm that you have set the font folder using the CellsHelper.setFontDir to generate the provided PDF. Moreover, the font setting statement was executed before creating an instance of Workbook.

By the way, as you are using Aspose.Cells for Java 8.8.0, I would request you to give the latest version a try on your end as well. Please note, the latest version is 8.9.2 at the moment whereas the font setting mechanism has been changed a bit. You can follow the article on Configuring Fonts for Rendering Spreadsheets to set the font directory with Aspose.Cells for Java 8.9.2. The latest version also includes the inspections APIs using which you can ensure that font files have been found by Aspose.Cells APIs.