zoukankan      html  css  js  c++  java
  • 打印 自定义纸张

     1 sr = new StringReader(str);
     2                 PrintDocument pd = new PrintDocument();
     3                 pd.PrintController = new System.Drawing.Printing.StandardPrintController();
     4                 PaperSize pageSize = new PaperSize("Custom", getYc(58), 600);//一定要Custom,写别的改变不了尺寸
     5                 pd.DefaultPageSettings.Margins.Top = 2;
     6                 pd.DefaultPageSettings.Margins.Left = 0;
     7                 pd.DefaultPageSettings.PaperSize = pageSize;
     8                 pd.PrinterSettings.PrinterName = pd.DefaultPageSettings.PrinterSettings.PrinterName;//默认打印机
     9                 pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    10                 pd.Print();
    11 
    12 ……………………………………
    13 
    14         //厘米转换英寸
    15         private static int getYc(double cm)
    16         {
    17 
    18             return (int)(cm / 25.4) * 100;
    19 
    20         }    
    21 
    22 
    23 
    24 
    25 private static void pd_PrintPage(object sender, PrintPageEventArgs ev)
    26         {
    27             Font printFont = new Font("Arial", 9);//打印字体
    28             float linesPerPage = 0;
    29             float yPos = 0;
    30             int count = 0;
    31             float leftMargin = ev.MarginBounds.Left;
    32             float topMargin = ev.MarginBounds.Top;
    33             String line = "";
    34             linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
    35             while (count < linesPerPage && ((line = sr.ReadLine()) != null))
    36             {
    37                 yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
    38                 ev.Graphics.DrawString(line, printFont, Brushes.Black,
    39                    leftMargin, yPos, new StringFormat());
    40                 count++;
    41             }
    42             // If more lines exist, print another page.
    43             if (line != null)
    44                 ev.HasMorePages = true;
    45             else
    46                 ev.HasMorePages = false;
    47         }
  • 相关阅读:
    2015第46周六
    2015年第46周五
    2015第46周四
    2015第46周三
    自己写shell命令pwd
    IOS成长之路-Nsstring搜索方法rangeOfString
    【Nginx】epoll事件驱动模块
    深入了解回调函数Java
    VS2008下直接安装Boost库1.46.1版本号
    oracle在schema是什么意思?
  • 原文地址:https://www.cnblogs.com/dyfisgod/p/7660109.html
Copyright © 2011-2022 走看看