Dear All I Try Sample Code & Add Test Code For Unicode Use Code Like this: '------------ Use ImageToPDF Demo Sample Code (VB2008) ----------------------------- Imports System.IO Imports PdfSharp Imports PdfSharp.Pdf Imports PdfSharp.Drawing
Public Class Form1 Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click Dim document As PdfDocument = New PdfDocument document.Info.Title = "Created with PDFsharp" Dim source As String = CurDir() & "\20110429143219_2.jpg" Dim img As XImage = XImage.FromFile(source) ' Create an empty page Dim page As PdfPage = document.AddPage ' Get an XGraphics object for drawing Dim gfx As XGraphics = XGraphics.FromPdfPage(page) gfx.DrawImage(img, 100, 100, 160, 120) gfx.DrawImage(img, 300, 100, 160, 120) ' Draw crossing lines Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0)) 'gfx.DrawMatrixCode(pen, New XPoint(20, 100)) gfx.DrawRectangle(pen, New XRect(100, 200, 400, 150)) ' Draw an ellipse gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5) ' Create a font Dim options As New XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always) Dim font As XFont = New XFont("標楷體", 20, XFontStyle.Bold, options) 'Dim font As XFont = New XFont("Times New Roma", 20, XFontStyle.Bold) ' Draw the text gfx.DrawString("Hello, World!", font, XBrushes.Black, New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormat.Center) '---------------------- Test UniCode ------------------------------- gfx.DrawLine(pen, New XPoint(0, 0), New XPoint(page.Width.Point, page.Height.Point)) gfx.DrawLine(pen, New XPoint(page.Width.Point, 0), New XPoint(0, page.Height.Point)) gfx.DrawString("世界你好!", font, XBrushes.Black, New XRect(0, 50, page.Width.Point, page.Height.Point), XStringFormat.Center) gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 150, 230) gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 160, 260) gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 170, 290) gfx.DrawString("這是測試 PDF 圖片檔案", font, XBrushes.Black, 180, 320) '---------------------------------------------------------------------- ' Save the document... Dim filename As String = "HelloWorld.pdf" document.Save(filename) ' ...and start a viewer. Process.Start(filename) End Sub End Class
|