报表rdlc怎样直接打印

JavaScript024

报表rdlc怎样直接打印,第1张

可以使用FlashViewer的以下两种方式来实现直接打印:

使用StartPrint 属性。展开FlashViewerOptions属性的,设置StartPrint 属性为True。

使用脚本实现

1. 首先设置FlashViewer的UserClientApi 属性为True。

2. 打开页面, 在OnLoadProgress事件中,添加以下脚本代码。你可以直接使用State属性来检测报表是否加载完成,并使用Print方法来调用系统的打印对话框。

具体的代码实现,请参考下面的博客

http://blog.gcpowertools.com.cn/post/printReport.aspx

实现Web打印报表的步骤:

首先,创建一个 Web 应用程序,添加 ActiveReports 报表到工程中,并在 aspx 页面中添加 WebViewer 控件

然后,设置 WebViewer 的 ViewerType 为 FlashViewer。

最后,在打印按钮单击事件的后台代码中设置 WebViewer1.FlashViewerOptions.PrintOptions.StartPrint = true,以实现加载报表之后直接打印。

具体的代码实现,请参考下面的博客

http://blog.gcpowertools.com.cn/post/ActiveReports_DirectPrint.aspx

[解决办法]

有解决方法实现一键打印..但是有个棘手的问题是:获取的打印机列表是服务器上的

代码如下:

使用系统

使用System.Collections.Generic

使用System.Data

使用System.Drawing.Imaging

使用System.Drawing.Printing

使用System.IO

使用System.Runtime.InteropServices

使用System.Text

使用Microsoft.Reporting.WinForms

命名空间RDLCPrinter

{

/// <summary>

///通过RDLC向默认打印机输出打印报表

/// </ summary>

public class BillPrint:IDisposable

{

/// <summary>

///当前打印页号

/// </ summary>

static int m_currentPageIndex

/// <summary>

/// RDCL转换流一页对应一个流

/// </ summary>

静态列表<Stream>m_streams

/// <summary>

///把报告输出成流

/// </ summary>

/// <param name =“report”>传入需要导出的报告</ param>

private void Export(LocalReport report)

{

string deviceInfo =

“<DeviceInfo>”+

“<OutputFormat>EMF </ OutputFormat>”+

//“<PageWidth>2in </ PageWidth>”+

//“<PageHeight>20in </ PageHeight>”+

“<MarginTop>0in </ MarginTop>“+

”<MarginLeft>0in <

“</ DeviceInfo>”

警告[]警告

m_streams = new List <Stream>()

report.Render(“Image”,deviceInfo,CreateStream,out warnings)

foreach(stream stream in m_streams)

stream.Position = 0

}

/// <概要>

///创建具有指定的名称和格式的流。

/// </摘要>

专用流CreateStream(字符串名称,串fileNameExtension,

编码方式进行编码,串mime类型,布尔willSeek)

{

流stream =新的FileStream(name +“。”+ fileNameExtension,

FileMode.Create)

m_streams.Add(流)

回流

}

/// <summary>

///打印输出

/// </ summary>

private void PrintPage(object sender,PrintPageEventArgs ev)

{

Metafile pageImage =

new Metafile(m_streams [m_currentPageIndex])

ev.Graphics.DrawImage(pageImage,ev.PageBounds)

m_currentPageIndex ++

ev.HasMorePages =(m_currentPageIndex <m_streams.Count)

}

/// <summary>

///打印预处理

/// </ summary>

private void Print()

{

PrintDocument printDoc = new PrintDocument()

string printerName = printDoc.PrinterSettings.PrinterName

if(m_streams == null

[解决办法]

m_streams.Count == 0)

return

printDoc.PrinterSettings.PrinterName = printerName

if(!printDoc.PrinterSettings.IsValid)

{

string msg = String.Format(“can not find printer”{0}“。”,printerName)

抛出新的异常(msg)

}

printDoc.PrintPage + = new PrintPageEventHandler(PrintPage)

StandardPrintController spc = new StandardPrintController()

printDoc.PrintController = spc

printDoc.Print()

}

public void Dispose()

{

if(m_streams!

= null) {

foreach(stream stream in m_streams)

stream.Close()

m_streams = null

}

}

/// <summary>

///对外接口,启动打印

/// </ summary>

/// <param name =“dtSource”>打印报表对应的数据源</ param>

/// <param name =“sReport”>打印报表名称</ param>

public static void Run(LocalReport report)

{

// LocalReport report = new LocalReport()

//report.ReportPath = @“.. \ ..”+ sReport

// ReportDataSource dataset = new ReportDataSource(“DataSet1”,dtSource)

//report.DataSources.Add(dataset)

m_currentPageIndex = 0

BillPrint billPrint = new BillPrint()

billPrint.Export(报告)

billPrint.Print()

billPrint.Dispose()

}

/// <summary>

///获取打印机状态

/// </ summary>

/// <param name =“printerName”>打印机名称</ param>

/// <param name =“status”>输出打印机状态</ param>

private static void GetPrinterStatus2(string printerName,ref uint status)

{

try

{

string lcPrinterName = printerName

IntPtr liHandle = IntPtr.Zero

if(!Win32.OpenPrinter(lcPrinterName,out liHandle,IntPtr.Zero))

{

Console.WriteLine(“print is close”)

返回

}

UInt32 level = 2

UInt32 sizeNeeded = 0

IntPtr buffer = IntPtr.Zero

Win32.GetPrinter(liHandle,level,buffer,0,out sizeNeeded)

buffer = Marshal.AllocHGlobal((int)sizeNeeded)

如果(!Win32.GetPrinter(liHandle,level,buffer,sizeNeeded,out sizeNeeded))

{

Console.WriteLine(Environment.NewLine +“Fail GetPrinter:”+ Marshal.GetLastWin32Error())

返回

}

Win32.PRINTER_INFO_2 info =(Win32.PRINTER_INFO_2)Marshal.PtrToStructure(buffer,typeof(Win32.PRINTER_INFO_2))

status = info。状态

Marshal.FreeHGlobal(缓冲液)

Win32.ClosePrinter(liHandle)

}

catch(异常ex)

{

throw ex

}

}

/// <summary>

///对外接口,调去打印机信息

/// </ summary>

/// <param name =“printerName”>打印机名称</ param>

/// <returns>返回打印机当前状态</ returns>

public static string GetPrinterStatus(string printerName)

{

uint intValue = 0

PrintDocument pd = new PrintDocument()

printerName = printerName ==“”?pd.PrinterSettings.PrinterName:printerName

GetPrinterStatus2(printerName,ref intValue)

string strRet = string.Empty

switch(intValue)

{

case 0:

strRet =“准备就绪(Ready)”

打破

case 4194432:

strRet =“被打开(Lid Open)”

打破

case 144:

strRet =“打印纸用完(out of paper)”

打破

case 4194448:

strRet =“被打开并且打印纸用完(缺纸&&盖打开)”

打破

案例1024:

strRet =“打印中(打印)”

打破strRet =“准备就绪(Ready)”打破case 4194432:strRet =“被打开(Lid Open)”打破case 144:strRet =“打印纸用完(out of paper)”打破case 4194448:strRet =“被打开并且打印纸用完(缺纸&&盖打开)”打破案例1024:strRet =“打印中(打印)”打破strRet =“准备就绪(Ready)”打破case 4194432:strRet =“被打开(Lid Open)”打破case 144:strRet =“打印纸用完(out of paper)”打破case 4194448:strRet =“被打开并且打印纸用完(缺纸&&盖打开)”打破案例1024:strRet =“打印中(打印)”打破strRet =“被打开(盖打开)”打破case 144:strRet =“打印纸用完(out of paper)”打破case 4194448:strRet =“被打开并且打印纸用完(缺纸&&盖打开)”打破案例1024:strRet =“打印中(打印)”打破strRet =“被打开(盖打开)”打破case 144:strRet =“打印纸用完(out of paper)”打破case 4194448:strRet =“被打开并且打印纸用完(缺纸&&盖打开)”打破案例1024:strRet =“打印中(打印)”打破case 4194448:strRet =“被打开并且打印纸用完(缺纸&&盖打开)”打破案例1024:strRet =“打印中(打印)”打破case 4194448:strRet =“被打开并且打印纸用完(缺纸&&盖打开)”打破案例1024:strRet =“打印中(打印)”打破

case 32768:

strRet =“初始化(初始化)”

打破

案例160:

strRet =“手工送纸(手动进纸)”

打破

case 4096:

strRet =“脱机(Offline)”

打破

default:

strRet =“未知状态(未知状态)”

打破

}

return strRet

}

}

public class Win32

{

[DllImport(“winspool.drv”,CharSet = CharSet.Auto,

SetLastError = true)] public static extern bool OpenPrinter(string printer,out IntPtr handle,IntPtr printerDefaults)

[DllImport(“winspool.drv”)]

public static extern bool ClosePrinter(IntPtr handle)

[DllImport(“winspool.drv”,CharSet = CharSet.Auto,SetLastError = true)]

public static extern bool GetPrinter(IntPtr handle,UInt32 level,IntPtr buffer,UInt32 size,out UInt32 sizeNeeded)

[StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)]

public struct PRINTER_INFO_2

{

public string pServerName

公共字符串pPrinterName

公共字符串pShareName

公共字符串pPortName

公共字符串pDriverName

公共串pComment

公共字符串pLocation

public IntPtr pDevMode

公共字符串pSepFile

公共字符串pPrintProcessor

公共字符串pDatatype

公共字符串pParameters

public IntPtr pSecurityDescriptor

公共UInt32属性

公共UInt32优先级

public UInt32 DefaultPriority

public UInt32 StartTime

public UInt32 UntilTime

public UInt32状态

公共UInt32 cJobs

public UInt32 AveragePPM

}

}

}