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         }
  • 相关阅读:
    (OK) usbip-utils
    How To Set Up A USB-Over-IP Server And Client With Ubuntu 10.04
    linux内核模块获取设备IP地址
    (OK) 国内常用NTP服务器地址及IP
    2017年我国将开始部署和建设IPv6地址项目
    C++之STL和Boost
    linux内核IOCTL网络控制框架实现分析
    2016年 AI 技术发展综述
    2016年SDN/NFV开源三大趋势
    Angular
  • 原文地址:https://www.cnblogs.com/dyfisgod/p/7660109.html
Copyright © 2011-2022 走看看