SiteMap  | About    

VB.NET Crystal Reports Export to PDF

Exporting from Crystal Reports to PDF format , we are using Crystal Reportss CrExportOptions . Also we have to set PdfRtfWordFormatOptions and ExportFormatType.PortableDocFormat . In the following example you can see how to export a Crystal Reports as a PDF format file.

All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure .

In this tutorial we are using our earlier program step by step Crystal Report for pull data from database to Crystal Reports . Before we start this section take a look at the step by step Crystal Report in VB.NET .

In the step by step Crystal Report we pull all data from Product table , here now we are exporting that data to a PDF format file.

Select the default form (Form1.vb) you created in VB.NET and drag two buttons (Button1, Button2 ) and CrystalReportViewer control to your form.

Select Form's source code view and import the following :

Imports CrystalDecisions.CrystalReports.Engine

Put the following source code in the button click events

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
    Dim cryRpt As New ReportDocument

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
        CrystalReportViewer1.ReportSource = cryRpt
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click
            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New _
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            CrDiskFileDestinationOptions.DiskFileName = _
            CrExportOptions = cryRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
        Catch ex As Exception
        End Try
    End Sub
End Class

cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.

When you run this program you will get the PDF file (crystalExport.pdf) in your computer's C: (C) 2015    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.