如何将报告转换为图像?

我使用Report viewer来显示我的报表。


现在我想将报告转换为图像。 如何将RDLC报告转换为稍后在其上绘制的图像。

有没有图书馆或方法可以做到这一点?

您必须创建ReportViewer的实例:

 ReportViewer report = new ReportViewer(); 

根据您要创建的报告类型设置适当的属性并传递所需的所有参数,例如:

 report.ProcessingMode = ProcessingMode.Remote; report.ServerReport.ReportPath = reportPath; report.ServerReport.SetParameters(reportParameters); 

现在您可以要求ReportViewer以您喜欢的格式呈现报告,它将返回一个字节数组,您只需将其流式传输到客户端或保存到某处:

 byte[] reportContent = report.ServerReport.Render(reportFormat); 

reportFormat是一个具有所需格式的string ,例如,要获取.TIF图像,您必须要求"IMAGE"格式,对于.PDF文件,您必须要求"PDF" (有关其他支持格式的MSDN,请参阅MSDN)取决于您使用的版本)。

现在,您只需将reportContent保存到文件中(或在响应中流式传输,添加适当的标头):

 System.IO.File.WriteAllBytes(path, reportContent);