Create pdf from crystal report

This article helps user to how to Create pdf from crystal report with code snippet

First create crystal report.In the interface of report i.e aspx form to display report,add report document as
Call the sub routine CreatePDF to display report.
rptProduct is the name of crystal report and docProd is the name of report document.

Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO

'This call is required by the Web Form Designer.
Private Sub InitializeComponent()
'start - This code should be pasted under #Region Private Sub itializeComponent()
'rptProduct is the name of crystal report.
Me.docProd = New rptProduct
Me.docProd.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation
Me.docProd.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize
Me.docProd.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper
Me.docProd.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default
'Ends here

'Declaration of report document
Protected WithEvents docProd As rptProduct

Private Sub CreatePDF()
Dim objDS As New DataSet
Dim dfdoFile As New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim strServerPath As String
Dim szFileName As String

'Create dataset as per requirement


szFileName = Session.SessionID & ".pdf" ' rptDailyCalls.pdf
strServerPath = MapPath("~") & "\Report\" ' Here the pdf file will be saved.
File.Delete(strServerPath & "\" & szFileName) ' Delete file first
dfdoFile.DiskFileName = strServerPath & "\" & szFileName
With docProd
.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
.ExportOptions.DestinationOptions = dfdoFile
End With
'URL of the pdf file
Response.Redirect("http://localhost/WebApplication1/" & szFileName ,Flase)
End Sub


Author: Parshuram17 May 2008 Member Level: Gold   Points : 2

But By defult Crystal report open in pdf

Author: Kumar Velu31 May 2008 Member Level: Gold   Points : 2

nice .. ,but change the title to export report to pdf..

Author: Ravindra PC21 Dec 2009 Member Level: Bronze   Points : 2

For C# Code Converting Crystal Report into PDF

Here Variables Are InputID is PDF Name, DocReport is Crystal Report and SavePath is destinationPath

public static void ConvertCrReportToPDF(string InputID, ReportDocument DocReport, string SavePath)
if (string.IsNullOrEmpty(SavePath))

ExportOptions exportOpts = new ExportOptions();
PdfRtfWordFormatOptions pdfFormatOpts = new PdfRtfWordFormatOptions();
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();

exportOpts = DocReport.ExportOptions;

// Set the PDF format options.
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.FormatOptions = pdfFormatOpts;

// Set the disk file options and export.
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
diskOpts.DiskFileName = SavePath + InputID + ".pdf";
// This is the path where the file will be saved
exportOpts.DestinationOptions = diskOpts;


Author: madhavi18 Mar 2010 Member Level: Silver   Points : 0

by default button is there for export option so why write code

Author: harrisandreson18 Mar 2010 Member Level: Bronze   Points : 1

I was astonished to see that what is the purpose of this site?

Author: Dilip18 Mar 2010 Member Level: Gold   Points : 1

Sometmies there is a requirement to create pdf directly from the web page.i.e. create pdf and display it directly on button click.This will avoid export to option used in crystal report.

Author: GuruRajan.K12 May 2010 Member Level: Gold   Points : 1


Nice, But Automatically Crystal report Export the RPT to PDF,

Then Why we Use this Code.


Author: VIVEK CHANDRA PRASAD10 Mar 2011 Member Level: Bronze   Points : 1

Thanks for your reply but my problem is i want to open print dialog box in All browser.
I have already used print mode="Active X" but it works only with IE not in Mozilla,Safari so plz help me how to do that .

Reply me its urgent!

Guest Author: anil14 Mar 2012

this is a very clear report.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: