Click here to Skip to main content
6,304,948 members and growing! (19,073 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

Convert a Crystal Report to PDF

By Jats_4ru

Export a report to PDF at runtime (Dynamically)
VB, .NET, Win2K, WinXP, Win2003, TabletPC, Visual Studio, Dev
Posted:28 Jun 2006
Updated:25 Jun 2007
Views:39,964
Bookmarked:18 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
17 votes for this article.
Popularity: 2.01 Rating: 1.64 out of 5
10 votes, 58.8%
1
1 vote, 5.9%
2
1 vote, 5.9%
3
2 votes, 11.8%
4
3 votes, 17.6%
5

Introduction

Export a report to PDF at runtime (Dynamically)

How to generate a report to PDF... I had this requirement and after my research i came up with this.

You can generate a PDF by Using a Crystal Report and piece of code....

First: Generate a Crystal Report as per your requirements.

Second: Use the below code to generate the PDF.

Place the following name spaces at the top of the code page

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Variable Declaration

Dim CrReport As New CrystalReport1() ' Report Name

Dim CrExportOptions As ExportOptions

Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()

Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()

Set the destination path and file name

CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf"

Specify a page range (optional)

crFormatTypeOptions.FirstPageNumber = 1 ' Start Page in the Report

crFormatTypeOptions.LastPageNumber = 3 ' End Page in the Report

crFormatTypeOptions.UsePageRange = True

Set export options

CrExportOptions = crReport.ExportOptions

With CrExportOptions

Set the destination to a disk file

.ExportDestinationType = ExportDestinationType.DiskFile

Set the format to PDF

.ExportFormatType = ExportFormatType.PortableDocFormat

Set the destination options to DiskFileDestinationOptions object

.DestinationOptions = CrDiskFileDestinationOptions

.FormatOptions = crFormatTypeOptions

End With

Trap any errors that occur on export

Try

Export the report

CrReport.Export()

Catch err As Exception

MessageBox.Show(err.ToString())

End Try

Thats it.... Now you are ready to create a PDF of the Report.

Hope it will be useful...

Plz add your comments and suggestions about the Article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jats_4ru


Member
Software Developer
Occupation: Web Developer
Location: India India

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
Generalthank you PinmemberLevi Erdmann12:41 13 Feb '09  
Answeranother way Pinmemberdespotovic2:20 5 Dec '08  
GeneralExport a report to PDF at runtime (Dynamically) PinmemberMember 45705183:49 24 Sep '08  
GeneralThis code doesn't work Pinmemberprashantds13:40 17 Jul '08  
QuestionCompiler Error Message: BC30002: Type 'CrystalReport1' is not defined PinmemberTim Vandeweerd7:58 19 May '08  
GeneralHelp Pls PinmemberSuresh Kumar.A0:02 9 Mar '08  
GeneralThanks a lot! Pinmemberpmartike2:06 11 Sep '07  
GeneralThanks Pinmemberfazo23:07 21 Sep '06  
GeneralI hate to critisize people PinmemberEnnis Ray Lynch, Jr.8:25 28 Jun '06  
GeneralAnd yes PinmemberEnnis Ray Lynch, Jr.8:26 28 Jun '06  
GeneralWhat Article ? PinmemberDarka2:54 28 Jun '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Jun 2007
Editor:
Copyright 2006 by Jats_4ru
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project