c# 調用zebra打印機指令打印條碼,若是直接打印到lpt1端口的打印機,經過copy指令沒有問題,c#
但若是ZEBRA打印機是經過USB鏈接,打印機端口爲usb001,則程序不能直接拷貝到usb001端口。windows
必須先共享本機的usb端口打印機,再將共享後的打印機名鏈接爲LPT端口打印機,則能夠成功打印。字體
from:ui
http://answers.microsoft.com/en-us/windows/forum/windows_7-hardware/how-do-i-print-a-file-to-my-usb-printer-in-windows/cc20646f-686c-4b45-9495-1d833b0f5fdaspa
一下是設置步驟:code
Set the printer to Shared, and make note of the name that you give it.
Then go to Start | Run, and enter the line
NET USE LPT1 \\name of your computer\shared name of printer
You will now be able to issue the command
COPY /b \path\filename.prn LPT1:blog
/b 參數不用也能夠。string
c#代碼it
private void button1_Click(object sender, EventArgs e) { string wo = "TEST002"; string tmpFile = "d:\\123.txt"; string prtName = @"\\WIN7-20140313GI\test"; StringBuilder str = new StringBuilder(); str.Append("^XA \r\n"); //打印命令開始 str.Append("^LL 600^FS \r\n");//定義標籤長度 105SL 300 DPI (1mm 12pt) 50mm*12 str.Append("^PW 1200 \r\n"); //定義標籤寬度 100mm*12 str.Append("^FO40,60^A@N,55,35,E:ARIALR.FNT^FDWO:" + wo + "^FS \r\n");//定義座標,字體 str.Append("^FO40,150^BY4,4^BCN,100,N,N,N,A^FR^FD" + wo + "^FS \r\n");//128碼 str.Append("^XZ");//結束打印 using (System.IO.StreamWriter sw = new System.IO.StreamWriter(tmpFile)) { sw.Write(str.ToString()); } System.IO.File.Copy(tmpFile, prtName, true); }