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 11, 2018 9:26 am

Hi support,

Basically this is my code to convert from txt file to pdf. After the conversion I got weird square symbols. Please also see attachment. Thanks!

Stream txtStream = new StreamReader(Server.MapPath("~/uploads/") + checkName, Encoding.UTF8).BaseStream;

document.LoadFromStream(txtStream, Spire.Doc.FileFormat.Auto);

ToPdfParameterList tpl = new ToPdfParameterList
{
UsePSCoversion = true
};
document.SaveToFile(Server.MapPath("~/uploads/") + checkName + ".pdf", tpl);
str.Add(checkName + ".pdf");

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Tue Sep 11, 2018 10:32 am

Hello,

Thanks for your post.
Please refer to below code to apply a font which supports rendering Chinese character, and the version I used is Spire.Doc Pack(hot fix) Version:6.8.16. If there is any question, welcome to write back.
Code: Select all
Stream txtStream = new StreamReader(@"sample.txt", Encoding.UTF8).BaseStream;
Document document = new Document();
document.LoadFromStream(txtStream, Spire.Doc.FileFormat.Auto);
ParagraphStyle style = new ParagraphStyle(document);
style.Name = "FontStyle";
style.CharacterFormat.FontName = "宋体";
style.CharacterFormat.FontSize = 20;
document.Styles.Add(style);

foreach (Section s in document.Sections)
{
    foreach (var obj in s.Body.ChildObjects)
    {
        if (obj is Paragraph)
        {
            (obj as Paragraph).ApplyStyle(style.Name);
        }
    }
}
ToPdfParameterList tpl = new ToPdfParameterList
{
    UsePSCoversion = true
};
document.SaveToFile("result.pdf", tpl);


Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Sep 12, 2018 1:31 am

It works!!! Thank you so much!!

However, this time I have tried to use your method for DOCX To PDF, same issue has occurred. Please see attachment. Thanks.

Regards,
Kevin

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Wed Sep 12, 2018 6:50 am

Hello Kevin,

Thanks for your quick response.
I used below code to test your document, but didn't find any problem. Please try it on your side. However, there occurred the "System.NullReferenceException" when using the PS method to convert. I already submitted it to our Dev team for analyzing , once there is any update, I will let you know, sorry for the inconvenience caused.
Code: Select all
Stream txtStream = new StreamReader(@"sample.docx", Encoding.UTF8).BaseStream;
Document document = new Document();
document.LoadFromStream(txtStream, Spire.Doc.FileFormat.Auto);
ParagraphStyle style = new ParagraphStyle(document);
style.Name = "FontStyle";
style.CharacterFormat.FontName = "宋体";
style.CharacterFormat.FontSize = 20;
document.Styles.Add(style);

foreach (Section s in document.Sections)
{
    foreach (var obj in s.Body.ChildObjects)
    {
        if (obj is Paragraph)
        {
            (obj as Paragraph).ApplyStyle(style.Name);
        }
    }
}
document.SaveToFile("result2.pdf",FileFormat.PDF);

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Sep 12, 2018 7:51 am

Thank you Lisa,

I got this error message after SaveToFile method call.
I am using dlls from Spire.Office Platinum Version:3.0

StackTrace = " at spr5584.1(String A_0, Single A_1, FontStyle A_2)\r\n at spr5584.1(String A_0, String A_1, Single A_2, FontStyle A_3)\r\n at spr5584.3(String A_0, Single A_1, FontStyle A_2, CharacterFormat A_3)\r\n at spr5584.0(CharacterFormat A_0, String A_1, ...

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Wed Sep 12, 2018 8:43 am

Hello Kevin,

Did you use the latest Spire.Doc 6.8.16? To help us reproduce your issue, could you please provide your system configuration (E.g. Win7 64-bit) and the region setting(E.g. China Chinese). Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Sep 12, 2018 9:11 am

Dear Lisa,

Yes I am using 6.8.16.
Windows 7 64 bit
Region: China Hong Kong

The flow is PDF converts to DOCX and then use the produced DOCX converts back to PDF

PDF to DOCX is working fine. But DOCX back to PDF is not.

Could you please try the attached file to PDF format? Thanks.

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Wed Sep 12, 2018 10:57 am

Dear Kevin,

Thanks for your feedback.
With the same settings, I still can't reproduce your issue on my side. Here I attached my testing application which includes my generated Pdf file (Myresult.pdf) for your reference. Please directly run the application and tell us your result.
http://www.e-iceblue.com/downloads/attachment/WebAppDocxToPdf.zip

Sincerely,
Nina
E-iceblue support team
User avatar

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

Thu Sep 13, 2018 2:26 am

Thanks Lisa,

Unfortunately, issue still occur via using your sample. Do I need to install "宋体" font on my pc? if so, how to install?

Thanks,
Kevin

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Thu Sep 13, 2018 2:40 am

Thanks guys, I fixed it. I changed the font name to this

style.CharacterFormat.FontName = @"新細明體";

Now it is working. But I still need to fix the UsePSCoversion issue

Thanks
Kevin

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Thu Sep 13, 2018 3:25 am

Dear Kevin,

Glad to hear that!
If I change the font to "新細明體", there will be no problem even using PS method to convert. Does the issue still exist on your side when you use PS method? Our Dev team will analyze your problem specifically. We will keep you informed about the progress.

Sincerely,
Nina
E-iceblue support team
User avatar

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

Thu Sep 13, 2018 5:30 am

Dear Nina,

PS seems working fine too! Thanks for the support.

Regards,
Kevin

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Thu Sep 13, 2018 5:53 am

Hi,

Thanks for your prompt reply.
If you have further question, welcome to write back.

Sincerely,
Nina
E-iceblue support team
User avatar

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

Fri Sep 14, 2018 6:16 am

Hi Support,

I have issue with this file converting from PDF to DOCX

PdfDocument pdf = new PdfDocument();
pdf.LoadFromStream(file.InputStream);
pdf.SaveToStream(s, Spire.Pdf.FileFormat.DOCX);

The error massage is: "System.InvalidOperationException: 'No fonts of this family are available."

Thanks,
Kevin

nkeung
 
Posts: 19
Joined: Fri Sep 07, 2018 8:36 am

Fri Sep 14, 2018 9:19 am

Hello Kevin,

Thanks for your post.
I tested your case with our latest Spire.Office Platinum (DLL Only) Version:3.8.6 and generated the correct Docx file( please refer to the attached result.zip ). I suggest upgrading to the latest version to have a try, and then tell us the result.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc