Click to See Complete Forum and Search --> : Export Crystal reports to PDF


vbnov
March 18th, 2008, 10:37 AM
Hi all,

I really really need your help here. I have a crystal report viewer and its working good.

My questions is:

Can I export the report to PDF from a reportviewer? If so, How can I do this programmatically?

Thanx

PeejAvery
March 18th, 2008, 11:02 AM
[ moved ]

HairyMonkeyMan
March 18th, 2008, 11:21 AM
If you can access the report object from the viewer (I don't use the viewer), you can export to pdf with the following routine:

ReportObject.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "c:\targetpdf.pdf")

Regards

vbnov
March 18th, 2008, 11:27 AM
Thnx for your reply. I greatly appreciate it.

What other way can I use without using report viewer. Bcoz I dont have to show the report for the user. All I need to do is generate the report, save it and send it as an attachment in an email.

I need to pass date parameters to generate the report.

HairyMonkeyMan
March 18th, 2008, 11:43 AM
I'm not an expert, but I think you would be going along the right lines by looking into the following classes:

Dim ExportOptions As CrystalDecisions.Shared.ExportOptions
Dim MailOptions as CrystalDecisions.Shared.MicrosoftMailDestinationOptions

Good luck :wave:

vbnov
March 18th, 2008, 05:18 PM
Thank you!

But I have a new problem now. I am using report document and dataadapter to fill the dataset.

Even though I have a SQL Query for the dataset, it pulls all the rows from the table.

Below is the code.



dbConnection.Open()
Dim Report As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim sqlAdap, fname As String

Report.Load(Server.MapPath("SR.rpt"), CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)

sqlAdap = "SELECT STARTDATE, ENDDATE, PREPAREDBY, PREPAREDDATE, AMOUNT, CURRENCY FROM SREPORTS WHERE CYID = '" & PID & "' AND STARTDATE = '" & SDate & "' AND ENDDATE = '" & EDate & "'"

Dim DSresults = New System.Data.DataSet()
Dim Adap As New System.Data.OleDb.OleDbDataAdapter()
Adap.SelectCommand = New System.Data.OleDb.OleDbCommand(sqlAdap, dbConnection)

Adap.Fill(DSresults, "SR")

fname = "C:\Rpts\SR" & PID & ".PDF"

Report.SetDataSource(DSresults)
Report.SetDatabaseLogon(USR, PWD)
Report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fname)

HairyMonkeyMan
March 19th, 2008, 04:59 AM
You might be better using a connection and command object to load the data into a datatable - theres no need for a dataset unless there is more than 1 table.