473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 6666
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

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

Similar topics

7
by: bclegg | last post by:
Hi, I have a Monitoring application that needs to output single line summaries to a local dot matrix printer loaded with line flow. ie. It will have exclusive use of the printer which is connected...
12
by: Peter Lin | last post by:
Hey, I am just wondering if anyone has got any idea of setting up a new class so that you could just print like the old ways with the printer class, since I am writing a program that really...
56
by: peng | last post by:
Hi, I am development a project using C#.Net. Inside application, it needs to print labels on different Zebra label printers on the network. I used a shell script, but it only worked on the...
13
by: ATJaguarX | last post by:
I have a Zebra S500 and multiple S600 label printers. http://www.zebra.com/id/zebra/na/en/index/products/printers/industrial_commercial/s600.html They are currently being used in our legacy...
1
by: franchdream | last post by:
IntPtr pBytes; Int32 dwCount; dwCount = szString.Length; pBytes = Marshal.StringToCoTaskMemAnsi(szString); string yang = Marshal.PtrToStringAnsi(pBytes); ........ WritePrinter(hPrinter, pBytes,...
24
by: Tony Girgenti | last post by:
Hello. Developing a Windows Form program in VS.NET VB, .NET Framework 1.1.4322 on a windows XP Pro, SP2. Before printing a document, i want to set the font to a font that is only available...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.