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.

Sat Mar 22, 2025 12:26 pm

Greetings,
I am using Spire.Xls 14.12.0 for python to convert an excel worksheet to pdf.
The issue is that the font (called Garuda) that is used when saving to pdf do not display Arabic characters correctly.
is there a way to set the embedded font when saving the worksheet to pdf?
The issue doesn't occur on on my windows development machine but it occurs when I push my code to the live Linux environment

Could you help with this issue please

Regards

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Mon Mar 24, 2025 1:43 am

Hello,

Thansk for your inquiry.
You can choose any of the following ways to solve your issue.
1. Install Garuda font in your linux environment.
2. Create a folder in your Linux environment to store Garuda fonts, and use the following code to specify the font directory. When converting, Spire.Xls will load font files from this folder.
Code: Select all
workbook = Workbook()
workbook.LoadFromFile(inputFile)
workbook.CustomFontFileDirectory= ["./the font folder"]
workbook.SaveToFile(outputFile, FileFormat.PDF)

If you have any further questions, please feel free to reply at any time.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Mon Mar 24, 2025 9:06 am

Greetings,

I implemented the provided code. The fonts are not loaded into the pdf.
Please note that the Garuda font is the one that is causing the trouble. It shows Arabic characters as squares
I want to load into the pdf any font that supports arabic like arial or traditional arabic or calibri.
If the issue that i mentioned is not related to font then please show me how to fix it.

Thank you
Regards

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Mon Mar 24, 2025 9:42 am

Hello,

Thanks for your reply.
May I ask what font was used in your original excel file? You need to install the font files used in the excel fileinto the system. If it still doesn't work, please provide us with your excel file for further investigation. You can upload it to the attachment or send it to this email: [email protected]. Thank you in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Mon Mar 24, 2025 1:28 pm

Greetings,

I used Arial in the excel workbook. The generated pdf on my dev machine (Windows) has Calibri as an embedded font and shows Arabic characters correctly.
When it is generated on the live environment (Linux) it will have Garuda as an embedded font and it does not show the Arabic characters correctly.

Thank you
Regards

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Tue Mar 25, 2025 1:02 am

Hello,

Thanks for your reply.
Firstly, please check if your Linux environment has installed Arial and Calibri fonts. If not, please install and retest. If it still doesn't take effect, please provide us with your excel file so that we can further investigate.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Thu Mar 27, 2025 2:05 pm

Greetings,
We have installed both fonts (Arial, Calibri) and it was not embedded in the pdf.
I think that when saving the workbook as pdf the code picks up a random font.
FYI Garuda font is specifically made for the Thai language.
Our linux enviroment (Ubuntu 24.04) has arabic fonts and many others.
ِAttached is a sample excel and the list of fonts that are installed in our linux enviroment

Thank you for your support. Appreciate it.
Regards
Attachments
list of fonts installed.zip
(4.72 KiB) Downloaded 595 times
riyadh_a0exgyf5.zip
(9.07 KiB) Downloaded 492 times

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Fri Mar 28, 2025 3:08 am

Hello,

Thanks for your inquiry.
Sorry, maybe the program thinks that the "Garuda" font is more suitable for Arabic drawing when judging the glyph. To avoid this issue, we recommend that you create a font folder and copy the Calibri font to this folder. Then specify the font folder with the following code, and the program will prioritize loading fonts from this font directory rather than the system font directory.
Code: Select all
from spire.xls import *
from spire.xls.common import *
workbook = Workbook()
workbook.LoadFromFile("riyadh_a0exgyf5.xlsx")
workbook.CustomFontFileDirectory= ["./fonts"]
workbook.SaveToFile("ToPdf.pdf", FileFormat.PDF)
workbook.Dispose()
The directory structure is as follows.

Sincerely,
William
E-iceblue support team
Attachments
directory-structure.png
directory-structure.png (4.83 KiB) Viewed 30 times
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Sun Apr 06, 2025 1:10 pm

Greetings,
Sorry for the late reply. I was in vacation.
I tried the suggested solution and it didn't work.
The lib does not prioritize the fonts in the folders. It always pick the fonts in the system.

Could you help with this issue?

Thank you
Regards

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Mon Apr 07, 2025 8:12 am

Hello,

Thanks for your reply.
Sorry, I did notice that the fonts of some content still changed after using the above method to convert. I have submitted this issue to our development team with the ticket SPIREXLS-5776. They will investigate further and I will inform you as soon as there is any progress.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Mon Apr 21, 2025 10:11 am

Hello,

Thanks for your patience.
Regarding issue SPIREXLS-5776, please refer to the code below for testing. Looking forward to your feedback.
Code: Select all
from spire.xls import *
from spire.xls.common import *

workbook = Workbook()
en=CultureInfo.CreateSpecificCulture("en-US")
CultureInfo.set_DefaultThreadCurrentCulture(en)
workbook.LoadFromFile("riyadh_a0exgyf5.xlsx")
print(workbook.CultureInfo.DisplayName)
sheet=workbook.Worksheets[0]
print(sheet.Range["E16"].Style.Font.FontName)
workbook.CustomFontFileDirectory= ["./fonts"]
workbook.SaveToFile("ToPdf.pdf", FileFormat.PDF)
workbook.Dispose()

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Tue Apr 22, 2025 10:32 am

Greetings,

I tried the suggested solution and it didnt work.

Regards

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Wed Apr 23, 2025 2:33 am

Hello,

Thanks for your feedback.
Have you changed your test file? Here I have uploaded the my project package. Please unzip it and execute the "test.py" file to check whether the generated PDF is correct. If not, please provide us with the generated PDF file to help us investigate further. Thanks in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Wed Apr 23, 2025 2:05 pm

Greetings,
For anyone having trouble with this, Here is the summary of what happened:
1. I did not understand how CustomFontFileDirectory functionality. Now I understand it. It tries to match the fonts that are in the excel with the ones in the directory if a font is matched it embeds it in the pdf if not it will embed the default (maybe?) font in the system.
2. To be safe and sure that the CustomFontFileDirectory functionality will work we need to include all of variants of the font (bold, italicbold,italic, ….etc ) if they are available.
3. Using a relative path in CustomFontFileDirectory is troublesome and I couldn’t find a way to check if it was pointing to the correct path or not, so I used an absolute path (os.path.join(os.path.dirname(__file__), "fonts"))

Hope it helps

Regards

blue4603
 
Posts: 7
Joined: Sat Mar 22, 2025 12:16 pm

Thu Apr 24, 2025 9:30 am

Hello,

Thanks for your your reply and summary. If you encounter any other issues with our product in the future, please feel free to write back at any time.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.XLS