C# 直接打印指定路径文件 + 可选择指定打印机
来源:互联网 发布:大连软件职业学院地址 编辑:程序博客网 时间:2024/06/05 13:31
public void PrinteTicketWithPath(string path) { try { streamToPrint = new StreamReader (path); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); if (core.PrinterTicket != null) { pd.PrinterSettings.PrinterName = core.PrinterTicket; } pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); // Print the document. pd.Print(); } finally { streamToPrint.Close() ; } } catch(Exception ex) { MessageBox.Show(ex.Message); } } // The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; String line = null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); // Iterate over the file, printing each line. while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null)) { yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } // If more lines exist, print another page. if (line != null) { ev.HasMorePages = true; } else { ev.HasMorePages = false; } }
core 是个获取本地属性的类, 包括可以读取可用打印机的名字
0 0
- C# 直接打印指定路径文件 + 可选择指定打印机
- 4Fang打印控件直接指定打印机打印网页
- C#使用指定打印机打印Word,Excel等Office文件和打印PDF文件的代码
- java 指定打印机 进行打印
- JAVA 指定打印机进行打印
- java 指定打印机 进行打印
- java 指定打印机 进行打印
- java 指定打印机 进行打印
- java 指定打印机 进行打印
- c#通过程序将文件直接送到打印机打印
- C# 指定默认的打印机
- 拷贝文件到指定路径 wince C#
- 拷贝文件到指定路径 wince C#
- C#获取指定路径的所有文件
- C#向指定路径写入文件
- java指定打印机名称进行打印
- js调用打印机打印指定内容
- 打印文件指定行
- 【NoSQL】NoSQL入门级资料整理(CAP原理、最终一致性)
- pass2word例子---------------学习FMDB使用
- 通过网络使用adb
- 关于兴趣、教育、敬业 与 职业道德 ——读 金旭亮、时寒冰博文有感
- pass2word例子---------------启动密码存储
- C# 直接打印指定路径文件 + 可选择指定打印机
- 2014.3.18
- String,StringBuilder与StringBuffer的区别
- 简单介绍抽屉效果
- CArray::SetSize 的用法
- macro
- Visual Studio 中两个窗体(WinForm)之间相互传值的方法
- Nexus5设备ROOT
- mysql 锁优化