Generating a PDF from Reporting Services without the Report Viewer

This post is primarily for Steve since he has been bugging me about it.  (Forgive the VB, but this is what I did the demos in).  Steve doesn't like doing SQLRS, but personally, I'd like to do more of it.  I just can't seem to come up with any clients that want to do it.

Any way, here is the process of creating the PDF without using the Report Viewer.

Create a reference to the Reporting Services Web Services then get a variable reference for it:

Dim ws As New SQLRS.ReportingService
Dim creds As New System.Net.NetworkCredential

Next set the authentication for the web service:

creds.UserName = "RSUser"
creds.Password = "SomePassword"
ws.Credentials = creds

Finally, set some of the web service variables for how you want the data rendered.  You don't have to set all of these, but you will have to pass them all in, so I just like to be clear about what I am doing:

Dim result() As Byte
Dim report As String = "/Sample Reports/Sales Order Detail"
Dim format As String = "PDF"
Dim historyid As String = Nothing
Dim devinfo As String = ""
Dim credentials() As SQLRS.DataSourceCredentials = Nothing
Dim showhide As String = Nothing
Dim encoding As String
Dim mimetype As String
Dim warnings() As SQLRS.Warning = Nothing
Dim reporthistoryparams As SQLRS.ParameterValue() = Nothing
Dim streamid() As String = Nothing
Dim sh As New SQLRS.SessionHeader
ws.SessionHeaderValue = sh

Next, get the result from the web service:

result = ws.Render(report, format, historyid, devinfo, parameters, _
            credentials, showhide, encoding, mimetype, reporthistoryparams, _
            warnings, streamid)

And stuff it into the workflow (in this case, open the PDF in your favorite browser):

Response.ClearContent()
Response.ContentType = "application/pdf"
Response.BinaryWrite(result)
Response.Flush()

And for the record Steve...No, I will not convert this to C# for you, and I feel no shame to post VB code.

Print | posted on Sunday, April 29, 2007 10:04 PM

Feedback

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Tim Hibbard at 4/30/2007 12:24 AM Gravatar
No shame in VB!! Amen!

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Steven Harman at 4/30/2007 11:17 AM Gravatar
Well, seeing as you did do me a favor by posting the example code - I suppose I can't complain (too loudly) about it being in VB. :)

Thanks Brian!

# Links (4/30/2007)

left by Member Blogs at 4/30/2007 9:08 PM Gravatar
.NET Generating a PDF from Reporting Services without the Report Viewer How many ways to do a String

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Aashish at 6/22/2007 3:17 PM Gravatar
If I need to merge 2 pdf files generated as above, what is the way to go?

# re: Generating a PDF from Reporting Services without the Report Viewer

left by shauki at 7/26/2007 4:59 PM Gravatar
Hi, i am trying to use this sample code but the parameters param in the signature of the render method does not accepts arrays, only one param at a time, what if i need to pass more than one, like 3.

Thanks,

shauki

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Netunes at 7/30/2007 11:33 AM Gravatar
This is for the c# developers


byte[] result;
string report = "/Sample Reports/Sales Order Detail";
string format = "PDF";
string historyid = null;
string devinfo = "";
SQLRS.DataSourceCredentials[] credentials = null;
string showhide = null;
string encoding;
string mimetype;
SQLRS.Warning[] warnings = null;
SQLRS.ParameterValue[] reporthistoryparams = null;
string[] streamid = null;
SQLRS.SessionHeader sh = new SQLRS.SessionHeader();
ws.SessionHeaderValue = sh;

result = ws.Render(report, format, historyid, devinfo, parameters, credentials, showhide, encoding, mimetype, reporthistoryparams,
warnings, streamid);

Response.ClearContent();
Response.ContentType = "application/pdf";
Response.BinaryWrite(result);
Response.Flush();

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Mateus at 9/4/2007 4:31 PM Gravatar
Hi, I having some trouble when generating the pdf, the browser returns the following message:

The file is damaged and could not be repaired.

Does anyone know why by any chance???


thanks,

# re: Generating a PDF from Reporting Services without the Report Viewer

left by G-Lo at 9/11/2007 2:38 PM Gravatar
I use this method; unfortunately it times out on me because I have many images I'm trying to load. Do you know of a way to write code to resize the images first before rendering the report?

Any suggestions would be appreciated!
Thanks!

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Lost at 2/6/2008 8:39 AM Gravatar
can someone give further clarification on SQLRS

# re: Generating a PDF from Reporting Services without the Report Viewer

left by Shanker Kana at 6/25/2008 4:30 PM Gravatar
Simply awsome posting!
Title  
Name
Email (never displayed)
Url
Comments   
Please add 4 and 8 and type the answer here: