Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Feb 03, 2022 11:04 pm

I have an excel report (xlsx) which I read into a com.spire.xls.Workbook.

All the text in the excel spreadsheet is in font Arial, and the spreadsheet contains some unicode characters.

If I save the workbook as an excel file (using workbook.saveToStream) it generates the excel file correctly and all text displays correctly in Arial, including cells with the unicode characters.
However, when I save the workbook as PDF (using workbook.saveToStream with FileFormat.PDF) the cells that contain unicode characters display in Times New Roman font instead of Arial.

How can I get the cells containing unicode characters to display using the cell formatted font of Arial?

Attached a simplified excel report showing how the data is retrieved from one worksheet and inserted into the report page (the data worksheet would normally be hidden). Since formulas are often used in retrieving the data from the Data worksheet we cannot use the excel superscript feature and need to use unicode characters.

I'm using Spire.XLS for Java. Code snippet for generating excel or PDF report:
//Save as pdf or excel depending on users selection
if (reportParameters.getReportDownloadFormat().equals(ReportParameters.DownloadFormat.PDF)) {
spireXlsWorkbook.saveToStream(response.getOutputStream(), FileFormat.PDF);
} else {
spireXlsWorkbook.saveToStream(response.getOutputStream());
}
Attachments
Support.zip
Simplified excel report showing how the data is retrieved from one workbook and inserted into the report page. Since formulas are often used in retrieving the data from the Data worksheet we cannot use the excel superscript feature and need to use unicode characters.
(16.43 KiB) Downloaded 388 times

karenv_datacom
 
Posts: 15
Joined: Thu Apr 08, 2021 2:09 am

Fri Feb 04, 2022 8:28 am

Hello,

Thanks for your inquiry.
I tested your Excel file with our latest Spire.XLS for Java Version:5.1.5 and found the font of unicode characters display in ArialUnicodeMS rather than Times New Roman. Here I attached my output Pdf for your reference. I guess that your test environment doesn't have the font ArialUnicodeMS installed so our Spire.XLS can't find it, then uses other font like Times New Roman to replace. I suggest that you install the ArialUnicodeMS in your system and try again. If there is still any issue, please provide your test environment (such as Win7, 64bit) and your output PDF for further investigation.

Sincerely,
Nina
E-iceblue support team
Attachments
result.rar
(24.3 KiB) Downloaded 388 times
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Mon Feb 07, 2022 10:02 pm

Thanks for your speedy response and the details therein.

The application is running as an Azure App Service, hosted in a Standard Linux container using Apache Tomcat application server. Unfortunately, with using a standard linux container (not a custom one) we cannot modify the standard set of fonts provided.

When running the application locally on my Windows machine it works fine and the unicode characters display in the correct Arial font in the PDF. So it is definitely an issue in that the needed font is not available in our Azure environment. So now we are exploring ways to make the required font available.

One option - if I added the font to the classpath or a directory within the source code, would Spire.XLS for Java pick it up from there?

If you have any other suggestions of how to make the required font available please let me know.

Many thanks

karenv_datacom
 
Posts: 15
Joined: Thu Apr 08, 2021 2:09 am

Tue Feb 08, 2022 2:07 am

Dear Karen,

Thanks for your feedback.
Our Spire.XLS provides the following two methods to specify the fonts, you could take one of them to test. If there is any question, please feel free to contact us.
Code: Select all
Workbook wb=new Workbook();
wb.loadFromFile("sample.xlsx");
//Specify the font folder
wb.setCustomFontFileDirectory(new String[]{"fontFolder"});
//Specify the font file path
wb.setCustomFontFilePaths(new String[]{"fontPath"});

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Fri Feb 11, 2022 12:01 am

I have tried setting the custom font file directory but unfortunately it does not solve my problem.

Attached are screenshots showing what fonts are available via the Linux VM container (only the DeJaVu font family) and what fonts I have added in the custom font file directory (all Arial font family as well as Segoe UI light).

Also attached is the report template (xlsx file) as well as the resulting PDF reports for the following scenarios: (if you open the PDF report in Adobe and go to File > Properties > Fonts you can see what fonts are being used in the file)

1. Running on local Windows machine: The PDF uses various Arial fonts as well as Segoe UI light. This report appears correct and reflects what is in the template.

2. Running as Azure App Service on Linux VM container WITHOUT the custom font file directory set: The PDF uses various DeJaVu Sans fonts as well as DeJaVu Math Tex Gyre (which I assume is being used for displaying the cells with unicode characters in them).

3. Running as Azure App Service on Linux VM container WITH the custom font file directory set: The PDF uses DeJaVu fonts and Segoe UI light. No Arial font is used.

Since in scenario 3 the Segoe font is being used this confirms that the custom font file directory is being referenced and used. However, it is still not applying an Arial font!

I have further tried setting the workbook default font name but this does not make a difference.

My latest code (Java):

//Save as pdf or excel depending on users selection
if (reportParameters.getReportDownloadFormat().equals(ReportParameters.DownloadFormat.PDF)) {
spireXlsWorkbook.setDefaultFontName("ArialMT");
spireXlsWorkbook.setCustomFontFileDirectory(new String[]{reportsFontsDirectory});
spireXlsWorkbook.saveToStream(response.getOutputStream(), FileFormat.PDF);
} else {
spireXlsWorkbook.saveToStream(response.getOutputStream());
}
}
Attachments
Details.zip
(1.18 MiB) Downloaded 637 times

karenv_datacom
 
Posts: 15
Joined: Thu Apr 08, 2021 2:09 am

Fri Feb 11, 2022 9:08 am

Hi,

Thanks for your detailed information.
I tested your new file but still didn't reproduce your issue. Both fonts Arial-BoldMT and ArialMT can be embedded successfully in generated PDF. I found the font you used is OTF format, I uploaded the fonts in my folder, please try them again on your side.


Sincerely,
Nina
E-iceblue support team
Attachments
attachment.zip
(2.43 MiB) Downloaded 399 times
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Tue Feb 15, 2022 2:13 am

Hi Nina
Thank you for all your help in trying to figure out the problem. The 'setCustomFontFileDirectory()' was a great help. I eventually got all the required fonts in this directory and it now works!
Thanks again

karenv_datacom
 
Posts: 15
Joined: Thu Apr 08, 2021 2:09 am

Tue Feb 15, 2022 3:51 am

Dear Karen,

Glad to hear from you.
If you need assistance in future, please feel free to contact us.
Wish you all the best :)

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.XLS

cron