Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Aug 17, 2015 6:57 am

When Adding English as watermark, it works good, but when add Chinese, the Watermark display as "????",can anyone help

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Mon Aug 17, 2015 7:54 am

Hello,

Thanks for your inquiry.
Please use the method to embed Chinese fonts in your pdf file.
Code: Select all
 String fontFileName = "simhei.ttf";
 PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);

Here is the full code for your reference.
Code: Select all
 PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("test.pdf");
            PdfPageBase page = doc.Pages[0];         
            String fontFileName = "simhei.ttf";
            PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);
            PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
            brush.Graphics.SetTransparency(0.3f);
            brush.Graphics.Save();
            brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
            brush.Graphics.RotateTransform(-45);
            brush.Graphics.DrawString("中文字体", trueTypeFont, PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
            brush.Graphics.Restore();
            brush.Graphics.SetTransparency(1);
            page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
            doc.SaveToFile("5622.pdf");


Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Aug 17, 2015 8:35 am

Thanks, man. but i got an error when PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);
it says Cannot open file: simhei.ttf for reading. How to solve this, man?

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Mon Aug 17, 2015 9:29 am

Hello,

Thanks for your reply.
Please check if you find the file simhei.ttf.
The file (simhei.ttf) is a kind of Chinese font file. If it is installed on your system, you can find it in this folder "C:\Windows\Fonts". Or you need to download it from the internet.
If you find it in this folder "C:\Windows\Fonts", you can use the below code:
Code: Select all
String fontFileName = "C:\\Windows\\Fonts\\simhei.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);

Or you can copy it to the folder"...\pdfTest\bin\Debug", then you can use the below code:
Code: Select all
String fontFileName = "simhei.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Aug 19, 2015 6:56 am

Hello,

Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Aug 19, 2015 10:04 am

Yes, thank you very much.

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Thu Aug 20, 2015 1:16 am

Hello,

Please feel free to contact us, if you have any questions or needs. We are here for help.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Aug 28, 2015 3:53 am

Hi Team,

Now I got another question, if content if watermark is really long, can it have multi lines?And When i user A3 size PDF, the watermark is not that good, only watermarked half of one page.Do you have any suggestion? Thanks in advance. page.Canvas.ClientSize are same although it is different size PDF file
Last edited by Ryan.Wang on Fri Aug 28, 2015 8:42 am, edited 1 time in total.

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Fri Aug 28, 2015 8:41 am

Hello,

Thanks for your inquiry.
1) Yes, you can. Please add \n to your watermark. Here is the sample code for your reference.
Code: Select all
    brush.Graphics.DrawString("中文字体1\n中文字体2中文字体3\n中文字体4中文字体5", trueTypeFont, PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));

2) I have tested your issue with the latest version of spire.pdf ( Spire.PDF Pack Version:3.5 ). It worked well in our side. Please download it and have a try. If the issue is still exist, please offer us your sample file and your sample code. It would be helpful to replicate the issue and work out the solution for you ASAP.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Aug 28, 2015 9:26 am

Hi Team,

Issue 1 has been solved. Thanks. About Issue 2, when use page.Canvas.ClientSize.Width , it is still the same although it is different size PDF. As our PDF File is confidential, could you send me your test file, and i will try it @ local.

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Mon Aug 31, 2015 2:35 am

Hello,

Thanks for your reply.
Here is the test file in the attachment. If your issue is still unsolved, you could remove the security data of your document and then offer it to us. You also can send it to us ( [email protected] ) via email. It would be helpful to replicate the issue and work out the solution for you ASAP.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue Sep 01, 2015 7:09 am

Code: Select all
  string PDFPath = @"C:\PDFLocation\" + attachmentname + Guid.NewGuid().ToString() + ".pdf"; ;
                                        FileStream WriteStream = File.Open(PDFPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                                        ReadWriteStream(attachmentFile.OpenBinaryStream(), WriteStream);
                                        PdfDocument doc = new PdfDocument();
                                        doc.LoadFromFile(PDFPath);


                                        foreach (PdfPageBase page in doc.Pages)
                                        {
                                            PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
                                            brush.Graphics.SetTransparency(0.3f);
                                            brush.Graphics.Save();
                                            brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
                                            brush.Graphics.RotateTransform(-45);
                                            brush.Graphics.DrawString(WaterMark, trueTypeFont, PdfBrushes.Black, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
                                            brush.Graphics.Restore();
                                            brush.Graphics.SetTransparency(1);
                                            page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
                                        }
                                        Stream contentStream = attachmentFile.OpenBinaryStream();
                                        //doc.SaveToFile(@"C:\LegalDatabasePDFLocation\" +Guid.NewGuid()+ "TestMark.pdf");
                                        doc.SaveToFile(PDFPath);

Code: Select all
private void ReadWriteStream(Stream readStream, Stream writeStream)
        {
            int Length = 256;
            Byte[] buffer = new Byte[Length];
            int bytesRead = readStream.Read(buffer, 0, Length);
            // write the required bytes
            while (bytesRead > 0)
            {
                writeStream.Write(buffer, 0, bytesRead);
                bytesRead = readStream.Read(buffer, 0, Length);
            }
            readStream.Close();
            writeStream.Close();
        }


Here is My code, is there any thing wrong?How can i get the actual size of the page?

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Tue Sep 01, 2015 8:02 am

Good news, i usesd version 3.5 dll files , the it works. But how can i remove "evaluation warning", do it ia a must have for free version?

Ryan.Wang
 
Posts: 8
Joined: Mon Aug 17, 2015 6:43 am

Tue Sep 01, 2015 8:32 am

Hello,

Thanks for your reply.
1) I Have tested your code about Watermark. There is no wrong.
2) For your requirement, here is the code for your reference.
float x1= page.ActualSize.Width;
float x2 = page.ActualSize.Height;
3) You could contact our sales team([email protected]) to get a temporary license file to remove the warning message and have a better evalution on our products.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Sep 07, 2015 7:40 am

Hello,

Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF