ReportViewer rendering a empty PDF (Just one white page)

你。 提交于 2019-12-11 03:34:32

问题


I have a Asp.Net MVC 4 project and I'm using ReportViewer to generate some reports.

Because there is low or none compatibility with ReportViewer in MVC, using Chrome and Firefox, my approach was render the ReportViewer in a PDF stream and simple returning the stream like this:

// using Microsoft.ReportViewer.WebForms.dll [10.0.0.0].

using (var viewer = new ReportViewer())
using (var bc = new MyBusinessClass())
{
    viewer.LocalReport.ReportEmbeddedResource = @"MyEmbeddedName";

    var dsobj = bc.GetData();

    var ds = new ReportDataSource("DsName", dsobj);
    var ps = new ReportParameterCollection();

    ps.Add(new ReportParameter("ParameterName", DateTime.Now));

    viewer.LocalReport.DataSources.Add(ds);
    viewer.LocalReport.SetParameters(ps);

    string deviceInfo = "some validated info";
    string mimeType, encoding, fileNameExtension;
    string[] streams;
    Warning[] warnings;

    var buffer = viewer.LocalReport.Render("PDF", deviceInfo,
        out mimeType, out encoding, out fileNameExtension,
        out streams, out warnings);

    return File(new MemoryStream(buffer), "application/pdf", "MyPdfName.pdf");
}

I have a few reports already and all render fine. But now I'm creating a new one using the same approach, but when I open the action the PDF is empty i.e. it is just one page and there is nothing in this page (is blank).

But if this isn't weird enough, now I test the same using IE(9) as browser, and the report rendered fine, so I decided to try in FireFox and get nothing too.

Questions:

So this is what I don't understand, I'm rendering in PDF before returning so why the browser can influence this?

Is possible force ReportViewer to throw exceptions if anything goes wrong? 'Cause now, don't get errors just a empty page.

And most important, how can I fix this problem (make work in Chrome)?


回答1:


This appears to be a bug in recent versions of Chrome. It was reported on October 14th, 2015 and appears to be fixed in recent builds.

For me, updating to Chrome 46.0.2490.80 solved the issue.

Source: https://code.google.com/p/chromium/issues/detail?id=543018



来源:https://stackoverflow.com/questions/33283147/reportviewer-rendering-a-empty-pdf-just-one-white-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!