Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm having a problem when showing SSRS report directly to PDF without ReportViewer.
In Chrome, it ended with javascript error "Fail to load resource", dark gray background and
partial loaded "loading image".

But it shows correctly on Firefox and Internet Explore.
If I use ReportViewer and choose save as PDF, it works fine.
What could be the solution?
I surfed on web for a long time and still can't get the solution.

This is my reference article:
Exporting a SQL Server Reporting Services 2005 Report Directly to PDF or Excel[^]

I'm using Visual Studio 2012 and running on localhost.
SSRS version is [11.0.3000.0]
Google Chrome is [Version 27.0.1453.116 m]

This is my C# function.

C#
private void PreviewPDF(string aReportCode, string aID)
        {
            PrepareCommonParameters();
            PrepareSpecificReportParameters(aReportCode, aID);

            bool allCredentialsSet;
            rptviewer.Reset();
            rptviewer.ServerReport.ReportServerCredentials = new ReportServerNetworkCredential();
            rptviewer.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["RSURL"].ToString());
            rptviewer.ServerReport.ReportPath = mReportPath;
            rptviewer.ServerReport.GetDataSources(out allCredentialsSet);
            rptviewer.ServerReport.SetParameters(mReportParameterCollection);

            string mimeType, encoding, extension, deviceInfo;
            string[] streamids; Microsoft.Reporting.WebForms.Warning[] warnings;
            string format = "PDF";
            deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>";
            byte[] bytes = rptviewer.ServerReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
            Response.Clear();

            if (format == "PDF")
            {
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-disposition", "filename=output.pdf");
            }
            else if (format == "Excel")
            {
                Response.ContentType = "application/excel";
                Response.AddHeader("Content-disposition", "filename=output.xls");
            }
            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.Flush();
            Response.Close();
        }


Update! I tried both Google Chrome built-in PDF viewer and Adobe Reader 11.
Same result.
Also tested in Safari and Maxthon.
Safari is working but Maxthon don't.

Please help. I need this to be work on Chrome.
Thanks in advanced,
Linn
Posted
Updated 2-Jul-13 22:27pm
v2

Try replacing all these lines in your code:
C#
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();


by this one instead:

C#
Response.BinaryWrite(bytes);
 
Share this answer
 
Comments
tslin89 3-Jul-13 23:44pm    
Thanks a lot Marc, this solved my problem.
I've checked and now I can direct export to PDF in all browsers (Chrome, FF, IE, Maxthon, Safari).
Marc Gabrie 4-Jul-13 12:48pm    
You're welcome! Glad to hear that worked. Cheers,
This fixed the output for saving - now will save as output.pdf - was saving as mywebpage.aspx but really was a PDF - just changed the aspx to PDF and it would be a PDF.

Still chopping off an image in the viewer in chrome.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900