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.

Wed Dec 04, 2019 6:55 pm

Hello All,

My files.zip


I've an issue with Chinese characters not saving to pdf from word.

I've tried direct SaveToFile/SaveToPdf methods , including chinese font, saving fonts but nothing worked. I'm using latest Spire.Doc nuget package

SP.Document document = new SP.Document();
document.LoadFromFile(fileName + ".docx");
document.SaveToFile(fileName + ".pdf", SP.FileFormat.PDF);

Method #2

ParagraphStyle style = new ParagraphStyle(doc);
style.Name = "FontStyle";
style.CharacterFormat.FontName = "宋体";
style.CharacterFormat.FontSize = 20;
doc.Styles.Add(style);

if(Config.LanguageValue.ToLower() == ApiConstants.LanguageCode.Chinese)
{
foreach (Section s in doc.Sections)
{
foreach (var obj in s.Body.ChildObjects)
{
if (obj is Paragraph)
{
(obj as Paragraph).ApplyStyle("FontStyle");
}
}
}
}
doc.SaveToFile(fileName + ".pdf", SP.FileFormat.PDF);

I've tried using IsEmbeddedAllFonts = true too but nothing worked. Please find the attached doc.

Appreciate your immediate help on this.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Thu Dec 05, 2019 2:48 am

Hi,

Thanks for your inquiry.
I have noticed the issue and posted it to our Dev team, we will let you know once there is any update.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Dec 05, 2019 7:27 am

Hi Betsy,

Thanks for the information. We are due for an User Acceptance release this friday and appreciate if it can be resolved quickly

Thanks,
Santhoshi.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Thu Dec 05, 2019 7:35 am

Hello All,

We have the same issue. Looking for immediate assistance.

Thanks,
Manoj.

mturumella
 
Posts: 21
Joined: Fri Jan 22, 2016 2:28 am

Thu Dec 05, 2019 9:53 am

Hi Santhoshi,

Note the font for the Chinese characters in your Word file was set as "Time New Roman" which doesn't support Chinese. If you directly convert the Word to PDF with MS Word, the font will be changed to a font which supports Chinese. With Spire, there are issues to change the font at present. And I am afraid it cannot be fixed in a short time due to the complexity of the issue at present.
Now there are two temporary solutions for you, one is changing the used font to a font which supports Chinese with MS Word manually. The another is changing the font with Spire. In your Word file, Chinese characters are placed in tables, and there are child tables embedded in table. So your code didn't work. Below is sample code for your reference:
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(FilePath + @"Journal_Tuesday, December 3, 2019.docx");

            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "MyStyle";
            style.CharacterFormat.FontName = "宋体";
            style.CharacterFormat.FontSize = 10;
            doc.Styles.Add(style);

            foreach (Section s in doc.Sections)
            {
                foreach (var obj in s.Tables)
                {
                    Table table = obj as Table;
                    foreach (TableRow row in table.Rows)
                    {
                        foreach (TableCell cell in row.Cells)
                        {
                            foreach (DocumentObject cobj in cell.ChildObjects)
                            {
                                if (cobj is Paragraph)
                                {
                                    Paragraph par = cobj as Paragraph;
                                    par.ApplyStyle("MyStyle");
                                }

                                //Find embedded table
                                if (cobj is Table)
                                {
                                    Table tableC = cobj as Table;
                                    foreach (TableRow rowc in tableC.Rows)
                                    {
                                        foreach (TableCell cellc in rowc.Cells)
                                        {
                                            foreach (DocumentObject cobjc in cellc.ChildObjects)
                                            {
                                                if (cobjc is Paragraph)
                                                {
                                                    Paragraph par = cobjc as Paragraph;
                                                    par.ApplyStyle("MyStyle");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            doc.SaveToFile("19826.pdf", FileFormat.PDF);


Sincerely,
Betsy
E-icbelue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Dec 05, 2019 9:58 am

Hi Manoj,

Since the structure of each document is unique, if your document is not same as Santhoshi's, please share it with us for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Dec 05, 2019 1:19 pm

Thanks Betsy for your prompt response, I'll try that and let you know.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Thu Dec 05, 2019 1:38 pm

Thank you, that worked!!!

Best Regards,
Santhoshi.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Fri Dec 06, 2019 2:02 am

Hi,

Glad to hear that the temporary workaround is acceptable to you.
Our Dev team will continue to work on the issue, once there is any update, I will inform you.
Have a nice day :) .

Sincerely,
Nina
E-iceblue support team
User avatar

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

Return to Spire.Doc