当前位置:编程学习 > C#/ASP.NET >>

.net winform程序调用zebra 105ls打印机打印出来的位置不正确,高手请!

    因项目需要,写意个打印二维码的程序,使用的打印机是zebra 105ls 纸张大小是2cm * 4cm的条码纸,打印出来的内容总是位于纸张的中间部分开始,但是我想打满整个纸张,想请大家帮忙。
    打印代码如下:
    class PrintService
    {
        public PrintService()
        {
            //将事件处理函数添加到PrintDocument的PrintPage中
            this.docToPrint.PrintPage += new PrintPageEventHandler(docToPrint_PrintPage);
         }

        //创建一个PrintDocument的实例 
        private System.Drawing.Printing.PrintDocument docToPrint =
         new System.Drawing.Printing.PrintDocument();

        private System.IO.Stream streamToPrint;
        string streamType;

        public void StartPrint(Stream streamToPrint, string streamType)
        {
            this.streamToPrint = streamToPrint;
            this.streamType = streamType;
        }

        private void docToPrint_PrintPage(object sender,
         System.Drawing.Printing.PrintPageEventArgs e)//设置打印机开始打印的事件处理函数
        {
            switch (this.streamType)
            {
                case "txt":
                    string text = null;
                    System.Drawing.Font printFont = new System.Drawing.Font
                     ("Arial", 35, System.Drawing.FontStyle.Regular);

                    // Draw the content.
                    System.IO.StreamReader streamReader = new StreamReader(this.streamToPrint);
                    text = streamReader.ReadToEnd();
                    e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, e.MarginBounds.X, e.MarginBounds.Y);
                    break;
                case "image":
                    System.Drawing.Image image = System.Drawing.Image.FromStream(this.streamToPrint);
                    int x = e.MarginBounds.X;
                    int y = e.MarginBounds.Y;
                    int width = image.Width;
                    int height = image.Height;
                    if ((width / e.MarginBounds.Width) > (height / e.MarginBounds.Height))
                    {
                        width = e.MarginBounds.Width;
                        height = image.Height * e.MarginBounds.Width / image.Width;
                    }
                    else
                    {
                        height = e.MarginBounds.Height;
                        width = image.Width * e.MarginBounds.Height / image.Height;
                    }
                    System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(x, y, width, height);
                    e.Graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
                    break;
                default:
                    break;
            }

        }
}

这里要说明的是 打印机设置的纸张宽度是3cm*5cm的,用word做一个3cm*5cm的页面打印出来能打满整个纸张,但是程序就不行,我在程序里明明就是从坐标0,0的位置开始的,但是打出来就是从纸张的一般的位置开始打印内容。 --------------------编程问答-------------------- 斑马打印机  一般不用这种打印方法吧,需要通过端口传打印命令去打印的
补充:.NET技术 ,  .NET Framework
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,