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;
}
}