有解決過類似問題的大神請留步,救救我吧。
-------分割-------
最近在做一個快遞標簽打印系統,使用.NET(C#)調用斑馬打印機【ZDesigner GK888t (EPL)】進行打印,程序實現的是連續打印,但實際打印機卻是打一張,停一下,退一點紙,然后下一張,再停一下,。。。依此類推。
因為是大批量的標簽,所以這個間隔不能忍受,嘗試了各種打印機屬性和選項的設置都沒有用。
百度看到有人說換成海鷗的驅動,測試后果然不再中間停頓,但業務方不是很接受這個方案(機器較多,換驅動的工作量也蠻大的),沒辦法只能找代碼的問題,測試發現即使把打印邏輯精簡到最簡也一樣會停頓,以下是打印兩頁最精簡的測試代碼,請幫我看看有什么不妥:
方案一:
using System.Drawing.Printing; using System.IO; using System.Windows.Forms; namespace PrintServer { internal static class Program { /// <summary> /// 應用程序的主入口點。 /// </summary> [STAThread] private static void Main(string[] args) { for (int i = 0; i < 2; i++) { Test(); } } private static void Test() { var printDocument = new PrintDocument(); printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); printDocument.PrinterSettings.PrinterName = "ZDesigner GK888t (EPL)"; printDocument.Print(); } private static void printDocument_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawLine(Pens.Black, 100, 100, 200, 200); } } }
方案二:
using System.Drawing.Printing; using System.IO; using System.Windows.Forms; namespace PrintServer { internal static class Program { /// <summary> /// 應用程序的主入口點。 /// </summary> [STAThread] private static void Main(string[] args) { Test(); } private static void Test() { var printDocument = new PrintDocument(); printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); printDocument.PrinterSettings.PrinterName = "ZDesigner GK888t (EPL)"; printDocument.Print(); } private static int _printedCount = 0; private static void printDocument_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawLine(Pens.Black, 100, 100, 200, 200); _printedCount++; e.HasMorePages = _printedCount < 2; } } }
使用了以上兩種方案進行打印測試,均會在兩頁之間有個明顯的暫停並且回紙。
