c# - 如何将报告转换为图像?

标签 c# asp.net .net image reporting-services

<分区>

我使用 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,它们取决于您的版本正在使用)。

现在您可以简单地将 reportContent 保存到一个文件中(或者将其流式传输到响应中,添加适当的 header ):

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

关于c# - 如何将报告转换为图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14013295/

相关文章:

c# - 委托(delegate)程序

c# - Include() ThenInclude() 在 Table Per Hierarchy 策略中抛出 "Sequence contains more than one matching element"异常

c# - 读取 XML 没有返回任何结果

c# - 获取 SimpleDB 属性而不循环遍历项目的所有属性

javascript - 为什么ajax不向 Controller 发送数据?

asp.net - 通过 ASP.NET 4.5 WebForms 中的 bundle.config 与 BundleConfig.cs 捆绑资源

c# - 单击按钮时在 SqlDataSource 中运行存储过程

c# - 从另一个线程关闭表单

javascript - Web 表单错误 : Maximum Request Length Exceeded

.net - 持续集成中的性能测试?