[转]ASP.NET水晶报表打印常用设置

Technorati 标签:

本文来源:http://www.51csharp.net/a/Report/2009/1109/162.html

ASP.NET水晶报表打印常用设置

   1.对当前的报表指定打印机 2.获取当前打印机纸张的来源 3.输出到打印机,及打印的设置

/// 
    /// 对当前的报表指定打印机
    /// 
    /// 当前显示报表的与格式化的对象
    /// 打印机名称
    /// 设置打印机纸张的方向
    /// 设置打印机纸张的大小
    /// 设置打印机的双面打印项
    private void SetPrintOptions(ReportDocument crvPrint, string Print_Name, int east, int size, int source)
    {
        try
        {
            CrystalDecisions.CrystalReports.Engine.PrintOptions printOptions = crvPrint.PrintOptions;
            printOptions.PrinterName = Print_Name;
            printOptions.PaperOrientation = (PaperOrientation)east;
            printOptions.PaperSize = (PaperSize)size;
            printOptions.PrinterDuplex = (PrinterDuplex)source;
            printOptions.PaperSource = this.GetSelectedPaperSource(Print_Name, ((PrinterDuplex)source).ToString());
        }
        catch (Exception E)
        {
            throw new ApplicationException("参数设置错误!" + E.Message);
        }
    }
    ///    
    /// 获取当前打印机纸张的来源   
    ///    
    /// 打印机名称   
    /// 纸张来源的名称   
    /// 
    
     
    public System.Drawing.Printing.PaperSource GetSelectedPaperSource(string Print_Name, string sourceName)
    {
        System.Drawing.Printing.PaperSource selectedPaperSource = new System.Drawing.Printing.PaperSource();     System.Drawing.Printing.PrinterSettings  printerSettings = new System.Drawing.Printing.PrinterSettings(); printerSettings.PrinterName = Print_Name;
        foreach (System.Drawing.Printing.PaperSource paperSource in printerSettings.PaperSources)
        {
            if (paperSource.SourceName == sourceName)
            {
                selectedPaperSource = paperSource;
            }
        }
        return selectedPaperSource;
    }
 
    ///    
    /// 输出到打印机,及打印的设置(调用前需指定打印机与纸张的来源)   
    ///    
    /// 当前格式化与加载报表数据的对象   
    /// 要打印的份数   
    /// 是否逐份打印   
    /// 要打印的起始页   
    /// 打印的结束页   
    /// 
    
       (责任编辑:51CSharp.net)
 
public bool Print_PaperSource(ReportDocument crvPrint, int pagSize, bool PageShare, int beginPage, int endPage)
    {
        try
        {
            crvPrint.PrintToPrinter(pagSize, PageShare, beginPage, endPage);
            return true;
        }
        catch (Exception E)
        { 
            throw new ApplicationException("打印错误!" + E.Message); 
           return false;
        }
    }
        ///    
        /// 输出到打印机,及打印的设置 
        ///    
        /// 当前格式化与加载报表数据的对象   
        /// 打印机名称   
        /// 要打印的份数   
        /// 是否逐份打印   
        /// 要打印的起始页   
        /// 打印的结束页   
        /// 设置打印机纸张的方向   
        /// 设置打印机纸张的大小   
        /// 设置打印机的双面打印项   
        /// 
    
       
public bool Print_PaperSource(ReportDocument crvPrint, string Print_Name, int pagSize, bool PageShare, int beginPage, int endPage, int east, int size, int source) 
{    
    try    
    {    
        SetPrintOptions(crvPrint, Print_Name, east, size, source);   
         crvPrint.PrintToPrinter(pagSize, PageShare, beginPage, endPage);   
         return true;   
    } 
    catch (Exception E)   
        {     
        throw new ApplicationException("打印错误!" + E.Message);    
         return false; 
        } 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值