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.

Fri Jan 29, 2021 1:29 pm

Hi,

I am using your FreeSpire.XLS 10.10.0 .NET library to convert xlsx to PDF on Android
( C# project is a Xamarin Form project)
using the following code

Worksheet sheet_sub = workbook_sub.Worksheets[0];
string pdfAddress2 = Path.Combine(pdfFolderPath, pdfFilesNum + ".pdf");
sheet_sub.SaveToPdf(pdfAddress2);

the workbook_sub itself is loaded from a xlsx file

What I found is that if the xlsx contains only english, the SaveToPDF call is successful.
However, if I added a single Chinese character e.g. (你) to the xlsx, the SaveToPDF call
throw exception as follows:

{sprᮠ: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at sprὤ.ᜀ (System.IO.Stream A_0) [0x00043] in <9336e97fddb24777b8cd70208785816a>:0
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.SaveToPdf (System.String fileName) [0x00068] in <9336e97fddb24777b8cd70208785816a>:0
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.SaveToPdf (System.String fileName) [0x0020e] in <9336e97fddb24777b8cd70208785816a>:0

Is there a solution for this problem ?

Thanks.

kfchengkf
 
Posts: 5
Joined: Fri Jan 29, 2021 7:48 am

Mon Feb 01, 2021 10:16 am

Hello,

Thanks for your inquiry and sorry for the late reply as weekend.
I created a Xamarin Form project and did an initial test with FreeSpire.XLS 10.10.0 ,but did not reproduce your issue. Please make sure that your Android device has the font that supports Chinese character. If the issue still exists after the font has been installed, please provide us with your input xlsx file to help us reproduce your issue.
Thanks in advance.
Here is my test code:
Code: Select all
 
string fontpath = "/storage/emulated/0/Download/HYH1GFM.ttf";
Workbook workbook_sub = new Workbook();
workbook_sub.LoadFromFile("/storage/emulated/0/Download/AndroidTest.xlsx"); //AndroidTest.xlsx includes Chinese character
workbook_sub.CustomFontFilePaths = new string[]{ fontpath};           
Worksheet sheet_sub = workbook_sub.Worksheets[0];
string pdfAddress2 = "/storage/emulated/0/Download/res.pdf";
sheet_sub.SaveToPdf(pdfAddress2);


I also added new Chinese characters to xlsx and then converted it to pdf.
Code: Select all
   
sheet_sub.Range["A1"].Text = "你好";
sheet_sub.Range["A1"].Style.Font.FontName = "HYWeiBeiF";

Thanks for your patience and cooperation.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Feb 03, 2021 12:27 pm

Hello Marcia,

I tried to added the line
string fontpath = "/storage/emulated/0/Download/kaiu.ttf";
workbook_sub.CustomFontFilePaths = new string[]{ fontpath};

to my project, but the result is still the same.

(I don't have the HYH1GFM.ttf file, so I used the kaiu.ttf copied from Windows 10's font folder)

I tried it on emulator as well as two mobile devices.

Could you clarify the sentence "make sure that your Android device has the font that supports Chinese character" ?
Do you mean I must install some font before it work on the mobile ?

In my excel, the font displayed is "Arial" when the Chinese character is in focus. I have no idea what font is required in the excel to display the Chinese characters.

Also, I am testing it on a samsung c7 proc mobile.

Do you have any advise ?

Thanks.

kfchengkf
 
Posts: 5
Joined: Fri Jan 29, 2021 7:48 am

Thu Feb 04, 2021 6:18 am

Hello,

Thanks for your feedback!

About the “kaiu.tff” font: Kindly note that “kaiu.tff” is a font that is supported only on the Windows OS, and is not supported on the Android OS. You need to use a font that supports Chinese character on the Android OS.

For the first question: If you have a Chinese character-supported font installed on your Android device before you run the application, even if you don’t specify the fontpath, you can convert the xlsx file to PDF successfully. If not, you will need to place the .ttf file specified by the fontpath, and then convert by specifying font.

For the second question: In fact, the “Arial” font does not support Chinese character. Although the Chinese character in your document display well by “Arial” on MS Office, however, MS Office actually use the “Arial Unicode MS” font which supports Chinese characters.

I recommend that you download a font which supports Chinese character in the Android environment, just like "HYH1GFM.ttf" or other else, and then test again. If the issue still exists after you use the font, please provide us with your input xlsx file to help us reproduce your issue. You can send it to us via email (support@e-iceblue.com).

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Feb 08, 2021 2:03 am

Hello,

Hope you are doing well!

How is the issue now? If it still exists, could you please provide your input xlsx file to help us reproduce your issue?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 09, 2021 7:55 am

Hello,

I used the font HYH1GFM and it worked.
However, the font is not like the Arial
Font. I just wonder if Android has built in
fonts for Chinese.
It seems that Google has the Noto Sans CJK fonts
And also the Noto Serif TC fonts. But I can't made these
Fonts work in my program.
Do spire xls work with these fonts ?

Another issue is that the output is different from
The desktop version of the same program.
In the desktop version, the pdf fit into 1 page.
In the android version, the width of the pdf span over several pages.

How can I solve this issue ?

Thanks !

kfchengkf
 
Posts: 5
Joined: Fri Jan 29, 2021 7:48 am

Tue Feb 09, 2021 9:30 am

Hello,

Thanks for your feedback!

For the first issue: Our Spire.Xls can work with the Noto Sans CJK font and the Noto Serif TC font.

For the second issue: Please provide your input file for us so that we can reproduce your issue. Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 09, 2021 10:01 am

Hello,
Thanks for the quick reply. I have sent you the excel.

Actually, it's a very simple excel with 2 testing
Lines only.

I have also sent you the code for testing the Google fonts
That doesn't work.

Thanks.

kfchengkf
 
Posts: 5
Joined: Fri Jan 29, 2021 7:48 am

Wed Feb 10, 2021 10:23 am

Hello,

I have received your email, and thanks for sharing information.

About the issue that the pdf span over several pages: When I converted your file to Pdf with Microsoft Excel, the result pdf also span over several pages, I have attached my result file. If you want to make the sheet in one page, please use workbook_sub.ConverterSetting.SheetFitToPage = true to achieve that.

I used NotoSansCJKsc-Medium.ttf and NotoSerifCJKtc-Black.ttf to test your excel file. The program ran successfully and could generate pdf file. But I did reproduce your issue (the program threw the error "Index was out of range") when I used NotoSansCJK-Regular.ttc and NotoSerifTC-Regular.otf you mentioned in your code and I have logged the issue in our issue tracking system with the ticket SPIREXLS-3118 for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
Attachments
form_template_1.zip
(29.15 KiB) Downloaded 140 times
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Feb 17, 2021 9:42 am

Hello Marcia ,

Unfortunately I still cannot create the pdf using the Noto serif fonts.
I have sent you an email .

Could you help ?

Thanks !

kfchengkf
 
Posts: 5
Joined: Fri Jan 29, 2021 7:48 am

Wed Feb 17, 2021 9:49 am

Hello,

Sorry Marcia is currently on the 7-day Chinese New Year Holiday(02/11/2021-02/17/2021). She will get back to you as soon as we come back to work on Feb 18, 2021. Thanks for your support and understanding.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Apr 30, 2021 9:18 am

Hello,

Greetings from E-iceblue!
Glad to inform you that we just released Spire.XLS Pack(Hotfix) Version:11.4.6 which fixes the issue SPIREXLS-3118, please download it from the following links to test on your side. Looking forward to your test result.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.XLS/11.4.6

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.XLS