469,645 Members | 1,526 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

How to print chinese characters using WritePrinter API on Zebra Printer

Hi All,
I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type DOCINFO
  4.   pDocName As String
  5.   pOutputFile As String
  6.   pDatatype As String
  7. End Type
  8.  
  9. Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
  10.     hPrinter As Long) As Long
  11. Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
  12.     hPrinter As Long) As Long
  13. Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
  14.     hPrinter As Long) As Long
  15. Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
  16.     "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
  17.     ByVal pDefault As Long) As Long
  18. Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
  19.     "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
  20.     pDocInfo As DOCINFO) As Long
  21. Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
  22.     hPrinter As Long) As Long
  23. Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
  24.     hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
  25.     pcWritten As Long) As Long
  26. Private Declare Function AbortPrinter Lib "winspool.drv" (ByVal _
  27.     hPrinter As Long) As Long
  28.  
  29.  
  30. Private Declare Function GetThreadLocale Lib "kernel32" () As Long
  31.  
  32. Public Function GetLCID(tStr As String) As Long
  33.     '
  34.     GetLCID = GetThreadLocale()
  35.     '
  36.     If GetLCID = 1033 Then '1033 for English (US) Locale ID
  37.         '
  38.         GetLCID = 0
  39.         '
  40.     ElseIf GetLCID = 2052 Then ' 2052 for Chinese (PRC) Locale ID
  41.         '
  42.         GetLCID = Len(tStr)
  43.         '
  44.     End If
  45.     '
  46. End Function
  47.  
  48. Private Sub Command1_Click()
  49.     '
  50.     PrintLotIDLabel "AB1234-56A", "", 1, True
  51.     '
  52. End Sub
  53.  
  54. Public Function PrintLotIDLabel(strLotId As String, strAdditionalText As String, intNumCopies As Integer, booRandomBarCode) As String
  55.  
  56. Dim lhPrinter As Long
  57. Dim lReturn As Long
  58. Dim lpcWritten As Long
  59. Dim lDoc As Long
  60. Dim MyDocInfo As DOCINFO
  61. Dim i As Integer
  62. Dim X As Printer
  63. Dim booPrinterFound As Boolean
  64. Dim strRandomBarCode As String
  65. Dim strID As String
  66. Dim strBarcodeText As String
  67. Dim strData As String
  68.  
  69.   PrintLotIDLabel = ""
  70.  
  71.   If booRandomBarCode Then
  72.     Randomize
  73.     strRandomBarCode = ""
  74.     For i = 1 To 10
  75.       strRandomBarCode = strRandomBarCode & Chr(Int((90 - 65 + 1) * Rnd) + 65)
  76.     Next i
  77.   End If
  78.  
  79.   booPrinterFound = False
  80.   For Each X In Printers
  81.     If (InStr(UCase(X.DeviceName), "ZEBRA") > 0) And (InStr(UCase(X.DeviceName), "300") > 0) Then
  82.       Set Printer = X
  83.       booPrinterFound = True
  84.       Exit For
  85.     End If
  86.   Next
  87.  
  88.   If Not booPrinterFound Then
  89.     PrintLotIDLabel = "This PC has no printer with both 'Zebra' and '300' in the name.  Labels will not print."
  90.     Exit Function
  91.   End If
  92.  
  93.   strLotId = UCase(strLotId)
  94.   strID = Left(strLotId & " ", 10)
  95.   strAdditionalText = Right(Space(20) & strAdditionalText, 21)
  96.  
  97.   lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
  98.   MyDocInfo.pDocName = strLotId & " - BarCodeLabel"
  99.   MyDocInfo.pOutputFile = vbNullString
  100.   MyDocInfo.pDatatype = vbNullString
  101.  
  102.   If booRandomBarCode Then
  103.     strLotId = strRandomBarCode
  104. '********************************************************************************************
  105. 'here if we assign chinese string to "strID variable" then it will shows ASCII characters
  106. 'and it's working fine with english string
  107.  
  108.     strID = "Verification Label - Scan Me"
  109.  
  110. '********************************************************************************************
  111.     '
  112.   End If
  113.  
  114.   For i = 1 To intNumCopies
  115.     lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
  116.     Call StartPagePrinter(lhPrinter)
  117.  
  118.     strData = "^XA" & vbCrLf
  119.     strData = strData & "^FO20,15^ATN^FD" & strID & "^FS" & vbCrLf
  120.     strData = strData & "^FO255,20^ARN^FD" & strAdditionalText & "^FS" & vbCrLf
  121.     strData = strData & "^FO35,60^BY3,2.5,95^B3N,N,,N,N^FD" & strLotId & "^FS" & vbCrLf
  122.     strData = strData & "^XZ" & vbCrLf
  123.     '
  124.     lReturn = WritePrinter(lhPrinter, ByVal strData, Len(strData) + GetLCID(strID), lpcWritten)
  125.     lReturn = EndPagePrinter(lhPrinter)
  126.     lReturn = EndDocPrinter(lhPrinter)
  127.   Next i
  128.  
  129.   lReturn = ClosePrinter(lhPrinter)
  130.  
  131.   If booRandomBarCode Then PrintLotIDLabel = strRandomBarCode
  132.  
  133. End Function
  134.  
  135.  
Oct 14 '09 #1
2 6372
Dököll
2,364 Expert 2GB
Greetings, Flying Kite!

Its likely you searched here prior, if you did not give that a while while you wait. Also, I would suggests writing the characters locall first, like on the form, then print to printer:

http://www.google.com/search?hl=en&r...th+vb6&spell=1
Nov 9 '09 #2
I am currently working on the same only printing from Oracle BI Publisher.

You need to convert and upload a truetype font of chinese characters into the printer using the ZDownload printer utility first (free download from the Zebra website).

The chinese font i uploaded needed about 3MB of memory.

Once you have this, look at the ZPLII programming reference for the ^CI command. This sets the character set. Something line ^CI28 will do multibyte chinese and it uses the font mappings loaded into memory to print the correct characters.

Hope that helps.
Feb 11 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Peter Lin | last post: by
1 post views Thread by franchdream | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.