C#将纵向内容打印到横向纸张上(打印旋转)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xiezhijie/article/details/82734940

遇到了一个打印问题,设计了一张标签,要打印的内容是纵向的,要打印在 宽*高=8cm*10cm 的标签纸上,结果在设计完后发现客户购买的是 宽*高=10cm*8cm 的标签纸,于是就尝试使用 e.PageSettings.Landscape = true 来进行横向打印,结果发现没用的,内容还是从上到下打印的,而且最下面被截掉了。

print.DefaultPageSettings.PaperSize = new PaperSize("ERPPaper", 315, 394);
print.PrinterSettings.DefaultPageSettings.Landscape = false;              

 折腾了半天,最终发现用一下两行代码可以完美解决问题:

e.Graphics.TranslateTransform(0, 315);  
e.Graphics.RotateTransform(-90.0F);     

整体代码如下: 

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            #region 80×100
           
            Font font15 = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Regular);
            Font font18 = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular);

            e.Graphics.TranslateTransform(0, 315);
            e.Graphics.RotateTransform(-90.0F);

            e.Graphics.DrawLine(Pens.Black, 5, 5, 311, 5); 
            e.Graphics.DrawLine(Pens.Black, 5, 5, 5, 390);
            e.Graphics.DrawLine(Pens.Black, 5, 390, 311, 390);
            e.Graphics.DrawLine(Pens.Black, 311, 390, 310 ,5);

            e.Graphics.DrawLine(Pens.Black, 62, 43, 155, 43);
            e.Graphics.DrawLine(Pens.Black, 62, 91, 155, 91);
            e.Graphics.DrawLine(Pens.Black, 62, 139, 288, 139);
            e.Graphics.DrawLine(Pens.Black, 62, 187, 155, 187);
            e.Graphics.DrawLine(Pens.Black, 62, 236, 155, 236);
            e.Graphics.DrawLine(Pens.Black, 75, 283, 155, 283);
            e.Graphics.DrawLine(Pens.Black, 62, 331, 288, 331);
            e.Graphics.DrawLine(Pens.Black, 100, 379, 288, 379);

            e.Graphics.DrawLine(Pens.Black, 211, 43, 300, 43);
            e.Graphics.DrawLine(Pens.Black, 211, 91, 300, 91);
            e.Graphics.DrawLine(Pens.Black, 211, 187, 300, 187);
            e.Graphics.DrawLine(Pens.Black, 211, 236, 300, 236);
            e.Graphics.DrawLine(Pens.Black, 211, 283, 300, 283);

            e.Graphics.DrawString("归属:", font15, Brushes.Black, 8, 21);
            e.Graphics.DrawString("品种:", font15, Brushes.Black, 8, 69);
            e.Graphics.DrawString("规格:", font15, Brushes.Black, 8, 113);
            e.Graphics.DrawString("匹数:", font15, Brushes.Black, 8, 161);
            e.Graphics.DrawString("原料:", font15, Brushes.Black, 8, 212);
            e.Graphics.DrawString("明细ID:", font15, Brushes.Black, 8, 259);
            e.Graphics.DrawString("日期:", font15, Brushes.Black, 8, 305);
            e.Graphics.DrawString("堆号区位:", font15, Brushes.Black, 8, 353);

            e.Graphics.DrawString("织厂:", font15, Brushes.Black, 157, 21);
            e.Graphics.DrawString("ID:", font15, Brushes.Black, 157, 69);
            e.Graphics.DrawString("重量:", font15, Brushes.Black, 157, 161);
            e.Graphics.DrawString("批号:", font15, Brushes.Black, 157, 212);
            e.Graphics.DrawString("区位:", font15, Brushes.Black, 157, 259);

            #endregion
        }

 

展开阅读全文

没有更多推荐了,返回首页