in

ASP.NET Weblogs

Gregory Rubinstein

Converting ASP.NET to PDF

 I probably wouldn't be wrong if I said that most developers every now and then are tasked to present specific data contained in a webpage as a PDF document. There are two ways to do it:

  1. using the functionality of CrystalReportViewer's toolbar - this toolbar provides a button, which does exactly that. However, to use this approach you would have to actually display the crystal report on the page.

  2. programmatically convert the Crystal Report object into a PDF document using the Crystal Reports API

Below is the code for the second approach:

Dim report As CrystalReport1 = New CrystalReport1
SqlDataAdapter1.Fill(DataSet11)
report.SetDataSource(DataSet11)
report.ExportToHttpResponse (ExportFormatType.PortableDocFormat, Response, False, "ExportedReport")

Comments

 

Nombulelo said:

I will come back if it workd to me also

August 14, 2008 3:31 PM
 

Dr Suess said:

           ReportDocument crRpt;

           string reportPath = "";  

           CrystalDecisions.Shared.DiskFileDestinationOptions cr_OutputToFile;

           string s_FileSavePath = "";

           string s_ReportName = "CertList";

           string s_DateTimeStamp = "";

           try

           {

               crRpt = new ReportDocument();

               cr_OutputToFile = new CrystalDecisions.Shared.DiskFileDestinationOptions();

               reportPath = Server.MapPath("Secure\\CIS\\rptMC_CertificationsList.rpt");

               s_DateTimeStamp = Convert.ToString(DateTime.Today.Month) + Convert.ToString(DateTime.Today.Day) + Convert.ToString(DateTime.Today.Year);

                s_DateTimeStamp +=  Convert.ToString(DateTime.Today.Hour)+Convert.ToString(DateTime.Today.Minute )+Convert.ToString(DateTime.Today.Second  );

               s_FileSavePath = Server.MapPath("Docs\\" + s_ReportName + s_DateTimeStamp + ".pdf");

               //crRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

              // crRpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

               //cr_OutputToFile.DiskFileName = s_FileSavePath;

              // crRpt.ExportOptions.ExportDestinationOptions = cr_OutputToFile;

               crRpt.Load(reportPath);

               crRpt.SetParameterValue("Start_Date", "02/01/2009");

               crRpt.SetParameterValue("End_Date", "02/10/2009");

               crRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "ExportedReport");

               //crystalReportViewer.ReportSource = crRpt;

               crRpt.Export();

               crRpt.Close();

               pv_HideButtons();

           }

           catch (System.Exception ex)

               {

               System.Console.WriteLine("{0} exception caught here.", ex.GetType().ToString());

               System.Console.WriteLine(ex.Message);

               }

           finally

           {

           }

The code works fine until I get to the line crRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "ExportedReport");

I can successfully bring the report up in the viewer

crystalReportViewer.ReportSource = crRpt;

but not translate it to pdf.

February 11, 2009 11:47 AM
 

divs said:

Could you please explain the second approach more detailed , like u have created object of crystalreport1

Dim report As CrystalReport1 = New CrystalReport1

Which dll contains this class?

September 2, 2009 8:14 AM

Leave a Comment

(required)  
(optional)
(required)  
Add