using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Configuration;
 using System.Web;
 using System.Web.Security;
 using System.Web.UI;
 using System.Web.UI.HtmlControls;
 using System.Web.UI.WebControls;
 using System.Web.UI.WebControls.WebParts;
 using System.Drawing;
 using System.IO;

 namespace Comm
 {
     public class Printer
     {
         private Font printFont;
         private Font titleFont;
         private StringReader streamToPrint;
         ;

         /// <summary>
         /// 设置PrintDocument 的相关属性
         /// </summary>
         /// <param name="str">要打印的字符串</param>
         public void print(string str)
         {
             try
             {
                 streamToPrint = new StringReader(str);
                 printFont = );
                 titleFont = );
                 System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
                 pd.DocumentName = pd.PrinterSettings.MaximumCopies.ToString();
                 pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pd_PrintPage);

                 pd.PrintController = new System.Drawing.Printing.StandardPrintController();
                 pd.Print();
             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }

         private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
         {
             ;
             ;
             ;
             float leftMargin = this.leftMargin;
             ;
             String line = null;
             linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
             while (count < linesPerPage &&
             ((line = streamToPrint.ReadLine()) != null))
             {
                 )
                 {
                     yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
                     ev.Graphics.DrawString(line, titleFont, Brushes.Black, leftMargin + , yPos, new StringFormat());
                 }
                 else
                 {
                     yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
                     ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
                 }
                 count++;
             }
             if (line != null)
                 ev.HasMorePages = true;
             else
                 ev.HasMorePages = false;

         }
     }
 }

c# 無彈窗调用打印机的更多相关文章

  1. Java jacob调用打印机打印word文档

    前面说了Java如何生成复杂的Word文档,今年记录下Java如何调用打印机打印word文档. 起初用的是自带的PrintJob,但是系统提供的打印机制并不成熟完整.网上的代码也是千篇一律,在我的打印 ...

  2. c# 调用打印机

    1.本地打印机 //添加引用并using System.Management; public static void AvailablePrinters() { ManagementScope ms ...

  3. ios 调用打印机

    源码 无意中玩一个demo发现调用了打印机  才发现ios有快速调用打印机的功能. if ([UIPrintInteractionController isPrintingAvailable] == ...

  4. C# 调用打印机打印文件

    C# 调用打印机打印文件,通常情况下,例如Word.Excel.PDF等可以使用一些对应的组件进行打印,另一个通用的方式是直接启用一个打印的进程进行打印.示例代码如下: using System.Di ...

  5. aspose调用打印机打印文档

    aspose很不错的插件,功能非常强大,用到了其中的aspose.word. 如何生成word文档,点击. 下面说说如何如何通过打印机打印文档. aspose提供了一个print方法,通过该方法可以直 ...

  6. js實現彈窗

    strSucc += "<br/><font color=\"red\">提醒您!在預設狀態下,Google Chrome 會阻止彈出式視窗自動在 ...

  7. C#&.Net干货分享- 构建PrinterHelper直接调用打印机相关操作

    namespace Frame.Printer{    /// <summary>    ///     /// </summary>    public class Prin ...

  8. 调用打印机Demo

      接口 PrintService 是 DocPrintJob 的工厂.PrintService 描述了打印机的功能,并可查询它来了解打印机支持的属性. Java代码   import java.io ...

  9. C# 调用打印机 打印 Excel

    打印 Excel 模板 大体思路,通过NPOI操作Excel文件,通过Spire将Excel转成图片,将图片传给系统打印. Spire是收费工具,在微软库中下载Free版本. #region 打印所用 ...

随机推荐

  1. mysql常用总结

    用户管理mysql>use mysql;查看mysql> select host,user,password from user ;创建mysql> create user zx_r ...

  2. November 4th Week 45th Friday 2016

    Problems are not stop signs, they are guidelines. 问题不是休止符,而是指向标. Most of the problems can be overcom ...

  3. SQL 存储过程 分页 分类: SQL Server 2014-05-16 15:11 449人阅读 评论(0) 收藏

    set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- ============================================= -- Au ...

  4. AlphaDict 软件公布

    今天 Release 了 1.1. 主要是移植到了 window 平台, 无须安装,直接执行. 对 UI 又一次进行了设计,应该比之前好看多了. 加入了 生词本 功能,方便 学习外语. ------- ...

  5. JSF学习五Ajax

    验证username(不能有下划线)和password(不能小于六位) 1.UserBean.java package ajax; import java.io.Serializable; impor ...

  6. Java NIO类库Selector机制解析--转

    一.  前言 自从J2SE 1.4版本以来,JDK发布了全新的I/O类库,简称NIO,其不但引入了全新的高效的I/O机制,同时,也引入了多路复用的异步模式.NIO的包中主要包含了这样几种抽象数据类型: ...

  7. Swift: Initialization-1

    初始化的过程包括为每一个存储属性设置一个初始值和其他步骤.通过定义构造函数来实现初始化的过程,跟oc的初始化函数不同,Swift的构造函数不返回一个值.它们的主要角色是确保一个类型的实例在初次使用前被 ...

  8. Robolectric Test-Drive Your Android Code

    Running tests on an Android emulator or device is slow! Building, deploying, and launching the app o ...

  9. Python之路【第十二篇】:JavaScrpt -暂无内容-待更新

    Python之路[第十二篇]:JavaScrpt -暂无内容-待更新

  10. git语言

    安装完成后,需要进一步设置用户名和email.因为git是分布式版本控制工具,因此需要每台开发机自报家门. $ git config --global user.name "Your Nam ...