locked
C# code to export to pdf using Crystal Report

    Question

  • Hi all,

     

    Does any one has the code in C# to export to pdf using Crystal Report.

     

    Thanks,

     

    J.

    Thursday, September 14, 2006 5:51 PM

Answers

  • Here is code to export to disk

    Report.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\report.pdf");

    Thursday, September 14, 2006 6:26 PM

All replies

  • Here is code to export to disk

    Report.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\report.pdf");

    Thursday, September 14, 2006 6:26 PM
  • Thank you. 

     

    J.

    Tuesday, September 19, 2006 12:06 PM
  • 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");

     

    crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\report.pdf");

    //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

    {

    }

    This code works to bring up a report in the report viewer (I have the report hard coded to an xml file) - but I get the following exception on the line: 

    crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\report.pdf");


    +  ex {CrystalDecisions.CrystalReports.Engine.InvalidArgumentException:
    Error in File C:\DOCUME~1\svegors\LOCALS~1\Temp\rptMC_CertificationsList {BF51C83E-9A77-4D9F-97AA-86C6C647ED15}.rpt:
    Invalid export DLL or export format. ---> System.Runtime.InteropServices.COMException (0x800002B4):
    Error in File C:\DOCUME~1\svegors\LOCALS~1\Temp\rptMC_CertificationsList {BF51C83E-9A77-4D9F-97AA-86C6C647ED15}.rpt:
    Invalid export DLL or export format.
       at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
       at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
       --- End of inner exception stack trace ---
       at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
       at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
       at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
       at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
       at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
       at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
       at QUESt_Healthcare_Management_System.ReportDisplayPage.btn_CertList_Click(Object sender, EventArgs e) in C:\Documents and Settings\svegors\My Documents\Visual Studio 2008\Projects\QUESt Healthcare Management System\QUESt Healthcare Management System\ReportDisplayPage.aspx.cs:line 662} System.Exception {CrystalDecisions.CrystalReports.Engine.InvalidArgumentException}


    Dr Suess
    Wednesday, February 11, 2009 4:56 PM
  •                 CrExportOptions = cryRpt.ExportOptions;
                    {
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions = CrFormatTypeOptions;
                    }

    view full source cide here

    http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-export-pdf.htm

    yang.
    Wednesday, June 10, 2009 11:18 AM
  • There is inbuilt option in crystalreport viewer(top left corner).
    Saturday, July 24, 2010 7:25 AM