Vb.Net-Informations.com

  VB.NET Crystal Reports Export to PDF




   Categories

    HOME
    VB.NET
    CSHARP

 
   














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


         VB.NET Source Code Download           Print Source Code
         VB.NET Crystal Reports Export to PDF - Download
        
VB.Net Tutorial

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
        CrystalReportViewer1.Refresh()
    End Sub

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

NOTES:

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:\

VB.NET Crystal Reports Related Contents
*     Sample Database and tables for Crystal Reports tutorials
*     Step by Step help for creating a simple Crystal Reports in VB.NET
*     VB.NET Crystal Reports from multiple tables
*     VB.NET Crystal Reports String parameter
*     VB.NET Crystal Reports Integer parameter
*     VB.NET Crystal Reports Date parameter
*     VB.NET Crystal Report Load Dynamically
*     VB.NET Crystal Reports Formula Fields
*     VB.NET Crystal Reports Summary Fields
*     VB.NET Crystal Reports Export to Excel
*     Email a Crystal Reports from VB.NET
*     Crystal Reports Without Database
*     Crystal Report from SQL Query String
*     Dynamic Crystal Reports from SQL Query String
*     Crystal Reports from XML File
*     Create a Subreport in Crystal Reports
*     Create a Subreport in Crystal Reports with Link
*     How to deploy Crystal Reports on Clinet Machine
*     How to create Crystal Reports installer using Merge Modules

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved