我尝试使用 WinAPI 而不是 (System.Drawing.Printing.PrintDocument) 来准备打印文档,因为 Graphic.DrawString 无法正确呈现高棉 Unicode。只有 TextRendering.DrawText 正确呈现它。我相信 Graphic 是 GDI+ 包装器,而 TextRendering.DrawText 使用的是 GDI。此外,PrintDocument 不适用于 TextRendering.DrawText。
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
(ByVal lpDriverName As String, ByVal lpDeviceName As String, _
ByVal lpOutput As String, ByVal lpInitData As DEVMODE) As Long
Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" (ByVal hdc As Long, ByVal lpdi As DOCINFO) As Long
Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'' Getting Printer hDC
Dim printHandler As Long = CreateDC(Nothing, "Send To OneNote 2010", Nothing, Nothing)
Dim docInfo As New DOCINFO
docInfo.cbSize = Len(docInfo)
docInfo.lpszDatatype = Nothing
docInfo.lpszOutput = Nothing
docInfo.lpszDocName = "Testing"
StartDoc(printHandler, docInfo)
StartPage(printHandler)
Dim g As Graphics = Graphics.FromHdc(printHandler)
TextRenderer.DrawText(g, "Hello World", Me.Font, New Point(10, 10), Color.Black)
EndPage(printHandler)
EndDoc(printHandler)
End Sub
这是我的尝试。它在这行代码上失败:Dim g As Graphics = Graphics.FromHdc(printHandler)
. 看起来 Long 是 64 位,而 IntPtr 是 32 位。
有什么解决方法吗?