Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Sep 21, 2021 4:18 am

I'm using the spire doc free version to generate an invoice in PDF format for a Japanese customer using a docx template. While working in windows OS its working perfectly ok and we are getting the invoice including the Japanese characters. but in Linux we are not getting the Japanese characters , instead we are getting only squares with question mark symbols. the code is included below, please help, its urgent

Document doc=new Document();

doc.loadFromFile("template.docx");
doc.replace("No. {{serialno}}", "178542345\n", true, true);
doc.replace("20{{YY}}年{{MM}}月{{DD}}日", "2021年09月17日", true, true);
doc.replace("{{Businessname}}","東京" , true, true);
doc.replace("{{Amount}}", "12345", true, true);
doc.isUpdateFields(true);

doc.saveToFile("Result.pdf");

christopher.yohan
 
Posts: 3
Joined: Tue Sep 21, 2021 3:35 am

Tue Sep 21, 2021 6:04 am

Hello,

Thanks for your inquiry.

Please kindly note that when using our Spire.Doc to convert Word to PDF, you need to make sure that all fonts used in the Word file have been installed in the system. Your issue should be caused by not installing Japanese fonts in Linux. Please check which font is used for Japanese characters, then install it and test again.

If the issue persists, to help us investigate further, please provide your original Word file. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Tue Sep 21, 2021 7:24 am

We already tried with fonts in Linux, but failed. Here i am attaching the template, could you please try it.

christopher.yohan
 
Posts: 3
Joined: Tue Sep 21, 2021 3:35 am

Tue Sep 21, 2021 9:53 am

Hello,

Thanks for your feedback.

After testing on Windows OS, by analyzing your Word file and the result file, I found that these fonts need to be installed: Arial, MS Gothic, Microsoft YaHei UI, SimSun and Times New Roman.

Then I installed these fonts on Linux for testing, but there are no squares with the question mark symbols in the generated PDF. Please make sure you have installed these fonts on Linux. Or we suggest that you can install all Windows fonts directly on Linux.

Besides, Spire.Doc also supports embedding private fonts when converting Word to PDF. You can also give it a try.


Sincerely,
Rachel
E-iceblue support team
User avatar

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

Thu Sep 23, 2021 4:06 am

Its worked, before i was attaching fonts on docx,Now i changed the approch and the below code solved issue,

**import com.spire.doc.Document;
**import com.spire.doc.PrivateFontPath;

Document document = new Document();
doc.loadFromFile("template.docx");
doc.replace("No. {{serialno}}", "178542345\n", true, true);
doc.replace("20{{YY}}年{{MM}}月{{DD}}日", "2021年09月17日", true, true);
doc.replace("{{Businessname}}","東京" , true, true);
doc.replace("{{Amount}}", "12345", true, true);
doc.isUpdateFields(true);

PrivateFontPath fontPath = new PrivateFontPath("required_japaneseFont","C:\\Users\\Administrator\\Desktop\\required_japaneseFont.ttf");
ToPdfParameterList toPdfParameterList = new ToPdfParameterList();
List pathList = new LinkedList<>();
pathList.add(fontPath);
toPdfParameterList.setPrivateFontPaths(pathList);
document.saveToFile("outputfile.pdf",toPdfParameterList);


Thanks for replaying to the mail and queries.

christopher.yohan
 
Posts: 3
Joined: Tue Sep 21, 2021 3:35 am

Thu Sep 23, 2021 5:47 am

Hello,

Thanks for your feedback.

If you encounter any problems related to our product in the future, just feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Return to Spire.Doc