Creating a PDF from Cyrstal Report Automatically

I have a simple report that requires special formatting that will be very easy to do in Crystal Reports.  However, what I need my user to do with the report is Fax it using our fax service.  So what I need to do is to generate the report based on criteria gathered from another system and then fax the report automatically.  The fax information is passed to the program when the report is generated.  I would like to be able to do this without having to display the report to the user and having them "Save" or "Exit" the report to trigger the faxing but if I have to I can live with it.  So basically here is what I am asking:

1. Can I create a PDF file using a Crystal Report without displaying the report to the user;
2. If I have to display the report, is there a way to disable features of Crystal such as Exporting, Saving, Printing?  Can I add a Link or Button to the "screen" to initiate the faxing which is not included as part of the report so when the report is converted to a PDF it is not included?

I already have the code I need for communicating with our Fax Service.  I just need the PDF file generated.  The application is a web app using ASP.NET (VS 2010 C#).

Any help is appreciated!
dyaroshAsked:
Who is Participating?
 
CluskittConnect With a Mentor Commented:
You can use the above to display the report with a CrystalReportsViewer (simply send it to the report instead of exporting). Then you can disable the report buttons at will. Then add a normal button to save, which you then code with the exact same code (you'll need to create the report again), only this time you do export it.
0
 
CluskittConnect With a Mentor Commented:
You don't need to display it. You can export it directly to PDF. Something along these lines:
(remember to add these lines at the top)
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

    Dim rpt As New ReportDocument
    Dim sPath As String = "C:\ThisIsMyReport.rpt"
    Dim sPath2 As String = "C:\ThisWillBeMyPDF.pdf"
    rpt.Load(sPath)
    rpt.SetParameterValue("MyParam1", MyParamVar1)
    rpt.SetParameterValue("MyParam2", MyParamVar2)
'etc

'You only need this next part if you connect to a database
    Dim ConInfo As TableLogOnInfo
    For Each tT As Table In rpt.Database.Tables()
      ConInfo = tT.LogOnInfo
      ConInfo.ConnectionInfo.UserID = "MyUserID"
      ConInfo.ConnectionInfo.Password = "MyPassword"
      ConInfo.ConnectionInfo.ServerName = "MyServerName"
      ConInfo.ConnectionInfo.DatabaseName = "MyDBName"
      tT.ApplyLogOnInfo(ConInfo)
    Next

'You only need this part if you connect to a DB AND have subreports.
    For Each Sec As Section In rpt.ReportDefinition.Sections
      For Each rpo As ReportObject In Sec.ReportObjects
        If rpo.Kind = ReportObjectKind.SubreportObject Then
          Dim srpt As ReportDocument = CType(rpo, SubreportObject).OpenSubreport(CType(rpo, SubreportObject).SubreportName)
          For Each tT As Table In srpt.Database.Tables()
            ConInfo = tT.LogOnInfo
            ConInfo.ConnectionInfo.UserID = "MyUserID"
            ConInfo.ConnectionInfo.Password = "MyPassword"
            ConInfo.ConnectionInfo.ServerName = "MyServerName"
            ConInfo.ConnectionInfo.DatabaseName = "MyDBName"
            tT.ApplyLogOnInfo(ConInfo)
          Next
        End If
      Next
    Next

    rpt.ExportToDisk(ExportFormatType.PortableDocFormat, sPath2)

Open in new window

0
 
dyaroshAuthor Commented:
Thanks for the info on exporting.  Turns out since I posted my question, a requirement has changed that will force me now to display the report.  Can I control what gets shown with the Report like you can with MS Report Write?  What I will need is to have only a Save and Print option but with the Save option I would want to override the default Save and Export to a PDF and then call the Fax Service Web Service.  Can this be done?
0
 
dyaroshAuthor Commented:
Thanks!
0
 
CluskittCommented:
Sure thing. We use something similar on a page we have. We've disabled exporting and printing on the viewer and use our own code to convert it and manipulate it. That should be enough for you to get started, but if you need more help, don't hesitate to ask. I know crystal stumped me a lot at the beginning.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.