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.

Wed Apr 26, 2017 8:14 am

您好,抱歉,請問一下,

TextBox3.Text,內容為中文,這樣的方式,中文會變亂碼。

程式碼如下:
'Create one page
'Dim page As PdfPageBase = doc.Pages.Add(PdfPageSize.A4, margin)
Dim page As PdfPageBase = doc.Pages(Wk_Loop)

Dim brush As 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(TextBox3.Text, New PdfFont(PdfFontFamily.Helvetica, 24), 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))

謝謝。

shami
 
Posts: 2
Joined: Wed Apr 26, 2017 8:04 am

Wed Apr 26, 2017 8:44 am

您好,

感謝咨詢。
當使用繁體中文的時候,這裡有2個解決方案能解決中文亂碼問題。
1)使用PdfCjkFontFamily中的MonotypeHeiMedium字體,下面是示範代碼供您參考。
Code: Select all
            PdfCjkStandardFont font = new PdfCjkStandardFont(PdfCjkFontFamily.SinoTypeSongLight, 12f);
            brush.Graphics.DrawString("您好,歡飲來到e-iceblue", font, PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));

2)使用PdfTrueTypeFont字體,下面是示範代碼供您參考。
Code: Select all
            Font font1 = new Font("Arial Unicode MS", 11f);
            PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(font1, true);
            brush.Graphics.DrawString("您好,歡飲來到e-iceblue", trueTypeFont, PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));

如果還有任何問題,歡飲隨時與我們聯繫。

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Sun Apr 30, 2017 10:22 pm

您好,問題以依回答的方式解決,感謝,謝謝。

shami
 
Posts: 2
Joined: Wed Apr 26, 2017 8:04 am

Mon May 01, 2017 2:37 am

您好,

感谢您的反馈。如果有其它问题,请联系我们。

Sincerely,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.PDF