Click here to Skip to main content
15,794,593 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Actually I have a report in Crystal Reports. What I want to do is, "When I click on a button then it will convert dat report into .pdf file into a specified location" :-\

I'm using C# (window application)
Updated 2-Feb-10 12:12pm


May be the following code will help you. Pass your loaded report file to the following function and probably it would open a pdf file.

Private Sub PrintInAcrobat(ByVal rptDoc As ReportDocument)
            Dim Fname As String
            Dim crExportOptions As ExportOptions
            Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
            rptDoc.PrintOptions.PaperSize = PaperSize.PaperA4
            rptDoc.PrintOptions.PaperOrientation = PaperOrientation.Portrait
            Fname = Server.MapPath(".") & "\" & Session.SessionID.ToString & ".pdf"
            crDiskFileDestinationOptions = New DiskFileDestinationOptions
            crDiskFileDestinationOptions.DiskFileName = Fname
            crExportOptions = rptDoc.ExportOptions
            With crExportOptions
                .DestinationOptions = crDiskFileDestinationOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
            End With
            Response.ContentType = "application/pdf"
        End Sub

Hope it helps!!
Share this answer
In my web project crystal reports in built print option was used
and on print a new web window gets opened in which All or Pages option is selected
If pages option selected values in From and To text box can be entered
I want to get these values to enter in to my database but could not find any event for inbuilt print button

So i decided to go with my own print button
which will open a new window from where i will select ALL or Pages
and if Pages is selected values in From and To textbox
that is from which page to which page i want my records in pdf

I used the above code in solution 1 to convert my report in to PDF
this converts all the records which are opened in report(.rpt)
i want to convert only few records like
4th to 8th only
Please suggest.

Share this answer
you can export a crystal repport to the specified format (.pdf)
with this code

CrystalReport1 cr = new CrystalReport1();

string n = "c:\your specified location";
cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, n);
Share this answer
Sandeep Mewara 11-May-10 15:30pm    
Why did you replied 3 months old post? Whats the use?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900