Asp.net-报表查看器以本地处理模式导出到图像

发布于 2024-12-15 16:54:25 字数 917 浏览 4 评论 0原文

我用来在本地处理模式下导出为图像的以下代码在

Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= hi." + "jpeg");
Response.BinaryWrite(byts);
Response.Flush();
Warning[] warnings;
string[] streamids;
string encoding;
string extension;
string mimeType = "image/png";'
string deviceInfo ="<DeviceInfo><OutputFormat>PNG</OutputFormat></DeviceInfo>";
byte[] byts = null;
byts = ReportViewer1.LocalReport.Render("Image", deviceInfo , out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= hi." + "jpeg");
Response.BinaryWrite(byts);
Response.Flush(); 

这里代码工作正常,但它没有将完整的报告导出为图像,只有第一页导出为图像,我看不到第二页作为图像, 请帮帮我 预先感谢

Shanmugapriya.D

The following code i am using to export as a image in local processing mode is

Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= hi." + "jpeg");
Response.BinaryWrite(byts);
Response.Flush();
Warning[] warnings;
string[] streamids;
string encoding;
string extension;
string mimeType = "image/png";'
string deviceInfo ="<DeviceInfo><OutputFormat>PNG</OutputFormat></DeviceInfo>";
byte[] byts = null;
byts = ReportViewer1.LocalReport.Render("Image", deviceInfo , out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= hi." + "jpeg");
Response.BinaryWrite(byts);
Response.Flush(); 

here code is working fine, but it does not export the complete report as a image, only the first page is exporting as image, i could not see the second page as a image,
Please help me out
Thanks in advance

Shanmugapriya.D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深府石板幽径 2024-12-22 16:54:25

您只能从 ReportViewer 控件获取一页的图像。您可以做的是为所有页面生成图像 - 通过更改控件的 CurrentPage 属性或使用 渲染重载 需要 CreateStreamCallback 例如

private Stream LocalReportCreateStreamCallback(string name, string extension,
      Encoding encoding, string mimeType,bool willSeek)
{
    var stream = new MemoryStream();
    m_pages.Add(stream);
    return stream;
}

在这种情况下,Render 方法会不断调用回调,直到页面完成,因此您将获得m_pages 集合填充了所有页面图像的数据。现在,您可能可以压缩所有这些图像并发送响应,或者您可以使用一些图像处理库将这些图像拼接在一起以形成一个大图像以返回(这不是一个好主意,因为它会给您的服务器带来相当大的负载)。

通常,如果您要创建预览之类的东西,那么最好的办法是缓存这些图像并返回包含这些图像超链接的 html。

You can only get image for one page from ReportViewer control. What you can do is to generate images for all pages - either by changing CurrentPage property of the control or using the Render overload that takes CreateStreamCallback such as

private Stream LocalReportCreateStreamCallback(string name, string extension,
      Encoding encoding, string mimeType,bool willSeek)
{
    var stream = new MemoryStream();
    m_pages.Add(stream);
    return stream;
}

In such case, Render method keeps calling on the call-back till on pages are finished and thus you will have your m_pages collection filled with data for all page images. Now, you can probably zip all those images and send across the response or you may use some image manipulation library to stitch those images together to form one big image to return back (not a good idea because it will put quite a load on your server).

Typically, if you are going to create pre-view sort of thing then good idea would be to cache those images and return the html that would contain hyperlinks to those images.

背叛残局 2024-12-22 16:54:25

尝试将 StartPage 元素添加到您的设备信息并将其设置为“0”。请参阅 http://msdn.microsoft.com/en-us/library/ms155373。 .aspx.

Try adding the StartPage element to your device info and set it to "0". See http://msdn.microsoft.com/en-us/library/ms155373.aspx.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文