user3514663
user3514663

Reputation: 11

How to export to PDF on the click of view report button of report viewer in vb.net

Can you please help me how can I add my own code to report viewer button so that it will export my data directly to PDF.

I got below answer in one of the thread want to know how this can be done.

you could create your own custom report viewing control. The control would be comprised of fields for report parameters and a button to generate the report. When a user clicks the button you could generate the report in the background. You could display the report as a PDF.

Upvotes: 1

Views: 3093

Answers (1)

delph_JW
delph_JW

Reputation: 71

To achieve what you're after I think you've two choices:

  • Use Report Server webservice directly to get required output for a PDF file
  • Use ReportViewer control and render PDF from it

If you can the use of the reportviewer control is probably the easier option to maintain. Depending upon your requirements you may need to mix elements of both approaches.

Option 1

See the answer supplied on this question for a nice starter solution for accessing web service directly

Reporting services: Get the PDF of a generated report

Option 2

Rendering the output of a ReportViewer control to a PDF involves simply rendering the Report Viewer output to a byte array, and then sending that to a MemoryStream object and writing to the Output Stream. Sample code below will take report currently configured in the report viewer control and generate a PDF directly into the current web page :

Warning[] warnings = null;
string[] streamids = null;
string mimeType = null;
string encoding = null;
string extension = null;
byte[] bytes = null;
bytes = ReportViewer1.ServerReport.Render("PDF", null, mimeType, encoding, extension, streamids, warnings);
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
Response.ContentType = "Application/pdf";
Response.BinaryWrite(ms.ToArray());
Response.End();

Upvotes: 3

Related Questions