简体   繁体   中英

ReportViewer rendering a empty PDF (Just one white page)

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 ie 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)?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM