Exemple #1
0
        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;
                }
            }
        }
        // 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;
                }
            }
        }