打印 自定义纸张

Posted 历史的尘埃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打印 自定义纸张相关的知识,希望对你有一定的参考价值。

 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         }

 

以上是关于打印 自定义纸张的主要内容,如果未能解决你的问题,请参考以下文章

各种误解解释纸张打印机操作系统等误解相关

打印机驱动程序 - 自定义纸张尺寸

打印 自定义纸张

水晶报表设置纸张大小

更改打印机默认纸张大小

自定义纸张 未验证