[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Creating a PDF from Cyrstal Report Automatically

Posted on 2012-09-13
5
Medium Priority
?
576 Views
Last Modified: 2012-09-13
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!
0
Comment
Question by:dyarosh
  • 3
  • 2
5 Comments
 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 2000 total points
ID: 38395271
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
 

Author Comment

by:dyarosh
ID: 38395520
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
 
LVL 18

Accepted Solution

by:
Cluskitt earned 2000 total points
ID: 38395542
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
 

Author Closing Comment

by:dyarosh
ID: 38395601
Thanks!
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 38395627
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question