// Gets the DLL version for the SDK ----------------------------------------------------------------- public string GetSDKVersion() { ZBRGraphics graphics = null; int engLevel, major, minor; string version = ""; try { graphics = new ZBRGraphics(); graphics.GetSDKVer(out major, out minor, out engLevel); if ((major + minor + engLevel) > 0) { version = major.ToString() + "." + minor.ToString() + "." + engLevel.ToString(); } } catch (Exception ex) { version = ex.ToString(); } finally { graphics = null; } return(version); }
public void CancelJob(string printerName, int jobID, out string errMsg) { errMsg = string.Empty; int errValue; ZBRGraphics graphics = null; try { graphics = new ZBRGraphics(); if (graphics.CancelJob(printerName, jobID, out errValue) == 0) { errMsg = "CancelJob failed. Error: " + errValue.ToString(); } } catch (Exception ex) { errMsg = "CancelJob exception: " + ex.Message; } finally { graphics = null; } }
public bool DrawPersonInfo(PrintParameter printPra, ref ZBRGraphics g) { //float X = 0; //float Y = 0; string[] pos; int iCountParams = printPra.printstr.Length; if (true) { for (int i = 0; i < iCountParams; i++) { pos = printPra.position[i].Split(','); //X = GetHPixel((float)Convert.ToDouble(pos[0])); //Y = GetVPixel((float)Convert.ToDouble(pos[1])); int X = Convert.ToInt32(GetHPixel((float)Convert.ToDouble(pos[0]))); int Y = Convert.ToInt32(GetVPixel((float)Convert.ToDouble(pos[1]))); int err = 0; g.DrawText((int)X, (int)Y, Encoding.Default.GetBytes(printPra.printstr[i]), Encoding.Default.GetBytes("宋体"), 8, 0, 0, out err); g.DrawText((int)X, (int)Y + 1, Encoding.Default.GetBytes(printPra.printstr[i]), Encoding.Default.GetBytes("宋体"), 8, 0, 0, out err); //ret = PrintText((int)X, (int)Y, printPra.printstr[i], 8, "宋体", false); //ret = PrintText((int)X, (int)Y + 1, printPra.printstr[i], 8, "宋体", false); } } return(true); }
public void PrintFrontSideOnly(PrintParameter pParas, string drvName, out int jobID, out string msg) { PrintFormatView pfv = new PrintFormatView(); jobID = 0; msg = string.Empty; int errValue; // value of 0 indicates no errors ZBRGraphics graphics = graphics = new ZBRGraphics(); try { if (graphics.InitGraphics(ASCIIEncoding.ASCII.GetBytes(drvName), "job", out jobID, out errValue) == 0) { msg = "Printing InitGraphics Error: " + errValue.ToString(); return; } LogHelper.WriteLog(typeof(ZBRPrinter), "InitGraphics 成功"); //数据位置 pfv.DrawPersonInfo(pParas, ref graphics); LogHelper.WriteLog(typeof(ZBRPrinter), "DrawPersonInfo 成功"); //头像位置 pfv.DrawPhoto(pParas, ref graphics); LogHelper.WriteLog(typeof(ZBRPrinter), "DrawPhoto 成功"); if (graphics.PrintGraphics(out errValue) == 0) { msg = "Printing PrintGraphics Error: " + errValue.ToString(); return; } LogHelper.WriteLog(typeof(ZBRPrinter), "PrintGraphics 成功"); } catch (Exception ex) { msg += ex.ToString(); System.Windows.Forms.MessageBox.Show(ex.ToString(), "PrintFrontSideOnly"); } finally { if (graphics != null) { // Starts the printing process and releases the Graphics Buffer if (graphics.CloseGraphics(out errValue) == 0) { msg = "Printing CloseGraphics Error: " + errValue.ToString(); } graphics = null; } } }
// Checks to see if any jobs are in the print spooler ----------------------------------------------- public bool IsPrinterReady(string drvName, int seconds, out string errMsg) { errMsg = string.Empty; bool ready = false; int errValue = 0; ZBRGraphics g; try { g = new ZBRGraphics(); for (int i = 0; i < seconds; i++) { if (g.IsPrinterReady(ASCIIEncoding.ASCII.GetBytes(drvName), out errValue) != 0) { ready = true; break; } else if (errValue != 0) { errMsg = "Error: " + errValue.ToString(); break; } Thread.Sleep(1000); } } catch (Exception ex) { ready = false; System.Windows.Forms.MessageBox.Show(ex.ToString(), "IsPrinterReady"); } finally { g = null; } return(ready); }
public bool DrawPhoto(PrintParameter printPra, ref ZBRGraphics g) { Image img = null; LogHelper.WriteLog(typeof(PrintFormatView), "photo path:" + printPra.personPhoto); if (printPra.personPhoto.Equals("") || !File.Exists(printPra.personPhoto)) { img = Properties.Resources.blank; } else { LogHelper.WriteLog(typeof(PrintFormatView), "printPra.personPhoto:" + printPra.personPhoto); img = MyImage.GetFile(printPra.personPhoto); //img = Image.FromFile(printPra.personPhoto); } if (img == null) { return(false); } int _fwhith = Convert.ToInt32(GetHPixel(20.0f)); int _fHight = Convert.ToInt32(GetVPixel(25.0f)); string[] pos = printPra.photoPos.Split(','); int X = Convert.ToInt32(GetHPixel((float)Convert.ToDouble(pos[0]))); int Y = Convert.ToInt32(GetVPixel((float)Convert.ToDouble(pos[1]))); //int ret = PrintPicture((int)X, (int)Y, printPra.personPhoto, (int)_fwhith, (int)_fHight); int errValue = 0; g.DrawImage(Encoding.Default.GetBytes(printPra.personPhoto), (int)X, (int)Y, (int)_fwhith, (int)_fHight, out errValue); return(true); }
// Printing on Both Sides --------------------------------------------------------------------------- public void PrintBothSides(string drvName, string frontText, string imgPath, string backText, out int jobID, out string msg) { jobID = 0; msg = string.Empty; int errValue; // value of 0 indicates no errors ZBRGraphics graphics = null; try { // Creates a Graphics Buffer graphics = new ZBRGraphics(); if (graphics.InitGraphics(ASCIIEncoding.ASCII.GetBytes(drvName), "job", out jobID, out errValue) == 0) { msg = "Printing InitGraphics Error: " + errValue.ToString(); return; } // Draws Text into the Graphics Buffer int fontStyle = FONT_BOLD | FONT_ITALIC | FONT_UNDERLINE | FONT_STRIKETHRU; if (graphics.DrawText(35, 575, ASCIIEncoding.ASCII.GetBytes(frontText), ASCIIEncoding.ASCII.GetBytes("Arial"), 12, fontStyle, 0xFF0000, out errValue) == 0) { msg = "Printing DrawText Error: " + errValue.ToString(); return; } // Draws a line into the Graphics Buffer if (graphics.DrawLine(35, 300, 300, 300, 0xFF0000, (float)5.0, out errValue) == 0) { msg = "Printing DrawLine Error: " + errValue.ToString(); return; } // Places an Image from a File into the Graphics Buffer if (graphics.DrawImage(ASCIIEncoding.ASCII.GetBytes(imgPath + "\\Zebra.bmp"), 30, 30, 200, 150, out errValue) == 0) { msg = "Printing DrawImage Error: " + errValue.ToString(); return; } // Sends Barcode Data to the Monochrome Buffer if (graphics.DrawBarcode(35, 500, 0, 0, 1, 3, 30, 1, ASCIIEncoding.ASCII.GetBytes("123456789"), out errValue) == 0) { msg = "Printing DrawBarcode Error: " + errValue.ToString(); return; } // Prints the Graphics Buffer (Front Side) if (graphics.PrintGraphics(out errValue) == 0) { msg = "Printing PrintGraphics Error: " + errValue.ToString(); return; } // Clears the Graphics Buffer if (graphics.ClearGraphics(out errValue) == 0) { msg = "Printing ClearGraphics Error: " + errValue.ToString(); return; } // Draws Text into the Graphics Buffer if (graphics.DrawText(30, 575, ASCIIEncoding.ASCII.GetBytes(backText), ASCIIEncoding.ASCII.GetBytes("Arial"), 12, fontStyle, 0, out errValue) == 0) { msg = "Printing DrawText Error: " + errValue.ToString(); return; } // Prints the Graphics Buffer (Back Side) if (graphics.PrintGraphics(out errValue) == 0) { msg = "Printing PrintGraphics Error: " + errValue.ToString(); return; } } catch (Exception ex) { msg += ex.ToString(); System.Windows.Forms.MessageBox.Show(ex.ToString(), "PrintBothSides"); } finally { if (graphics != null) { // Starts the printing process and releases the Graphics Buffer if (graphics.CloseGraphics(out errValue) == 0) { msg = "Printing CloseGraphics Error: " + errValue.ToString(); } graphics = null; } } }