Home » Visual Studio

How to Export a Crystal Report to a PDF file Programmatically in vb.net

i try below code


Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared


'In Class

Dim customerReport As ReportDocument

customerReport = New ReportDocument()

Dim reportPath As String = Application.StartupPath & "\" & "CustMonthly.rpt"   ' I saved my report in the "\BIN\Debug" dir


Dim strPath As String

Dim strFileName As String

'Filename made up of customer number, year, month

strFileName = strCust & "_" & intYear.ToString & "_" & intMonthStart.ToString

'Path to save pdf report to and filename saved as

strPath = Application.StartupPath & "\reports\" & strFileName & ".pdf"

customerReport.ExportToDisk(ExportFormatType.PortableDocFormat, strPath)


and my code is 

szCurrDir = CurDir.ToString

            'In Class

            Dim customerReport As ReportDocument

            customerReport = New ReportDocument()

            Dim reportPath As String = szCurrDir & "\Other Report\repRD_Excel_Genrat.rpt"   ' I saved my report in the "\BIN\Debug" dir


            Dim strPath As String

            Dim strFileName As String

            'Filename made up of customer number, year, month

            strFileName = "Try"

            'Path to save pdf report to and filename saved as

            strPath = szCurrDir & strFileName & ".pdf"

            customerReport.ExportToDisk(ExportFormatType.PortableDocFormat, strPath)



Error is................ Missing parameter values.

plz help me anyone..............plz





2 Answers Found


Answer 1

Dear Sam,

I've checked your code, it contains 2 small errors. The reason this is not working is probably because the file "CustMonthly.rpt" is not in the debug directory or because the "Reports" folder does not exist. To fix the first, go to the properties of the *.rpt file, then set "Copy To Output Directory " to "Copy Always ". If you expand your code as demonstrated below, it will work. If this was helpfull and or the answer, please mark it as such.




Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.SharedImports System.IO
PublicClass SomeReport
  PrivateSub CheckOutPutFolder()
    TryIfNew System.IO.DirectoryInfo(Path.Combine(Application.StartupPath, "Reports")).Exists = FalseThen
        Directory.CreateDirectory(Path.Combine(Application.StartupPath, "Reports"))
      EndIfCatch ex As Exception
    EndTryEndSubPublicSub RunMyReport()
    If System.IO.File.Exists(Path.Combine(Application.StartupPath, "CustMonthly.rpt")) = TrueThenDim customerReport AsNew ReportDocument()
      Dim reportPath AsString = Path.Combine(Application.StartupPath, "CustMonthly.rpt")
      With customerReport
        .ExportToDisk(ExportFormatType.PortableDocFormat, Path.Combine(Application.StartupPath, "MyReport.pdf"))
      MessageBox.Show("Your rpt was not found in the following folder: " & vbCrLf & Application.StartupPath)



Answer 2

Hi Sam,

I am moving this thread to "Crystal Reports for Visual Studio" forum for better support.


Best Regards,



Hi, all:

It is pretty straight forward to export Crystal Report to PDF file, or other files.

protectedvoid btnCrystalReport_Click(object sender, EventArgs e)


   string pID;

   string filePath;

   string sDate;

   ReportDocument rd = newReportDocument();

   pID = tbPID.Text;

   filePath = Request.ServerVariables["APPL_PHYSICAL_PATH"];

   sDate = DatePicker.SelectedDate.ToShortDateString();

   rd.Load(filePath + "FiberMaster.rpt");

   rd.SetParameterValue("Rev", sDate);

   rd.SetParameterValue("PID", pID);

   rd.SetDatabaseLogon("myUser", "myPassword");

   rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "ExportedReport");

   //rd.ExportToDisk(ExportFormatType.PortableDocFormat, @"C:\ASP.NET\temp\myfirstCR.pdf"); //OK, it works.


Enjoy and good luck.

Stanley Huang

I am using crystal report in asp.net 2.0.
I got proper alignment in crystal report but when i export report to PDF, the alignement get disturbed.

Please help me ASAP.


Hi all,

Does any one has the code in C# to export to pdf using Crystal Report.



We are using an existing rpt file and changing the datasource to an XML source via a url. The following code runs fine on my local machine but fails when deployed on our remote development box. I have installed the CR SP2 runtime engine files (including the crdp_xml.dll that isn't included) and the java runtime engine files and supporting directories (see article for this at http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/13732). <--Code Snippet---> public void ExportRptToPdf() { try { ReportDocument rpt = new ReportDocument(); rpt.Load(RptInputFilePath); DataSet data = new DataSet(); XmlDocument xml = new XmlDocument(); String URLString = "---url string hidden---"; XmlTextReader reader = new XmlTextReader(URLString); data.ReadXml(reader); rpt.SetDataSource(data); ExportOptions CrExportOptions; DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); CrDiskFileDestinationOptions.DiskFileName = RptInputFilePath; CrExportOptions = rpt.ExportOptions; { CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions; CrExportOptions.FormatOptions = CrFormatTypeOptions; } rpt.Export(); <------------fails at this line of code rpt.Close(); rpt.Dispose(); } catch (Exception ex) { _log.Error(ex.Message); _log.Error(ex.ToString()); } } <--- Error on Dev Server ---> Invalid Argument provided. Error in File reportfile {D327F753-1719-4E5E-984D-982A4BFF06CD}.rpt: Invalid argument for database. CrystalDecisions.CrystalReports.Engine.InternalException: Invalid Argument provided. Error in File reportfile {D327F753-1719-4E5E-984D-982A4BFF06CD}.rpt: Invalid argument for database. ---> System.Runtime.InteropServices.COMException: Invalid Argument provided. Error in File reportfile {D327F753-1719-4E5E-984D-982A4BFF06CD}.rpt: Invalid argument for database. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) --- End of inner exception stack trace --- at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export() at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export() at line 382 Thanks in advance for any help or comments given.

I have a Crystal Report that contains a field within a text object (to control line spacing) and has "can grow" selected. When I export the Crystal Report to a PDF there are instances when the text is cut off.

truncated test

In this example the text is being cut off on the right side, but in some cases, when the text consists of many lines, the bottom part of the last line will be partially cut off.

I am using Crystal Reports that is bundled with Visual Studio 2008. The text area has "can grow" checked, the font is set to Helvetica LT Condensed, bold 14, and the line spacing is set to 0.75 times normal. Anyone have any thoughts on how can I fix this?



I have a web portal which i want to use to expose some SQL Server 2008R2 SSRS Reports to my users who will login.

I want a situation where the users will click on a link and a dialog box will pop up , asking the user to save the generated PDF Report.

A parameter would have been used to generate this report.

Any ideas on this would be appreciated..Thanks.


Hi, I want to embed pdf file within crystal report. I have succssfully embed the image using XML schema file. It works fine. If I use the same technique for importing pdf file, it comes with blank screen. I have followed the following procedure. 1. Created xml schema file, <?xml version="1.0" encoding="utf-8"?><xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">  <xs:element name="RevsCert">    <xs:complexType>      <xs:sequence>        <xs:element name="Id" />        <xs:element name="pdf" type="xs:base64Binary" minOccurs="0" />      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema> 2. Included schema file using database export. 3. Created new subreport within main report and link to dataset created using step 2. 4. Dynamically passing the datastram to the datarow of the dataset. Code snippets for this as below: Private Sub EmbedFile(ByVal sSubReport As String, _                                  ByVal sFileName As String, _                                  ByVal sSource As String, _                                  ByVal sSchemaFile As String)         Dim xmlFile As String = Server.MapPath(sXmlPath & sSchemaFile)        Dim ds As New DataSet        ds.ReadXml(xmlFile)         Dim dc As DataColumn = New DataColumn(sSource, GetType(Byte()))        ds.Tables(0).Columns.Add(dc)         Dim fs As New FileStream(sFileName, FileMode.Open)  ' create a file stream         Dim br As New BinaryReader(fs)        ' create binary reader         For Each dr As DataRow In ds.Tables(0).Rows            dr(sSource) = br.ReadBytes(br.BaseStream.Length)        Next        reportDocument.OpenSubreport(sSubReport).SetDataSource(ds)        fs.Close() End Sub Calling above method as below: strFileName = Server.MapPath("../revcert/revcert_sample.pdf") EmbedFile("RevsCert", strFileName, "pdf", "revscert.xml") When I run the report, it show blank. If i change the pdf to some jpg or bmp file, It comes with image, but not work for PDF file. I appreciate someone help me to fix it. Thank you for your time.  

I wonder if someone can provide us with some help with what appears to be a Windows Vista compatibility issue. We have an application written in VB.NET 2003 which has built in Crystal reports. When we install the application on a Windows Vista PC everything appears to run fine except if we try to export a report to Excel. We get the following error reported "Error detected by export dll". The report exports fine to PDF, DOC and RTF. The installation and application works fine on Windows 2000 and Windows XP without any problems and the rest of the application appears to run fine on Vista. We have now conducted the test on 2 Windows Vista Business PCs and both have the same issue.

I have searched the Internet and specifically searched the Crystal support site but nobody seems to have reported the same issue.

Any thoughts? Does anybody actually have this working?



i've created a crystal report and one crystal report viewer in windows form.

i've two form form1 and form2 in form2 i've kept one button called print.

when i press this button it should print the document into .pdf format.

without using the crystal report viewers print button.

please help me below is my runtime figure.

where form2 consist button1 which is a print button.

when i press i should get the preview of the report in pdf format.

 please help me.



I tried to install VB.net 2008 from web http://www.microsoft.com/visualstudio/en-us/products/2008-editions

after that, I try to add crystal report 2008 component to VB.net .

By right click on toolbox choose items and checked crystal report viewer

It doesn't seem works, there is no crystal report 2008 component on toolbox


not works on Visual Studio 2008 eval version?


Thank you!



I am trying to create a report using vb.net 2008 but the report tab is not on (Toolbox, data tab). how do i get the report tab without having to loose my project. I tried the links you''ve given before but nothing seems to help.

when i use crystal report viewer ,i got problem with unicode.
so i need use it with Crystal Report ActiveX Viewer.
it's work fine but it's not dynamic.
i want to know how to change connection string at runtime for Crystal Report ActiveX Viewer.
thz for ur help.


Hi everyone!

I have VS 2008 SP1 and i have Crystal Reports installed.

I have a single form with a Crystal Report Viewer, I created a report with the wizard, and i want to show it in the report viewer, but it keeps showing blank. The DB is a MDB, and the code i have in the form that loads the data is the following:

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    Dim conn AsNew OleDb.OleDbConnection
    conn = New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=|DataDirectory|\Scilla10.accdb")
    Dim Strcmdsel AsString = "SELECT * from Muestras"Dim cmd AsNew OleDb.OleDbCommand(Strcmdsel, conn)
    Dim da AsNew OleDb.OleDbDataAdapter(cmd)
    Dim ds As DataSet = New DataSet("Muestras")
    Dim rptdocument AsNew CrystalDecisions.CrystalReports.Engine.ReportDocument
    da = New OleDb.OleDbDataAdapter(Strcmdsel, conn)
    Dim strReportPath AsString = "CrystalReport1.rpt"

    CrystalReportViewer1.ReportSource = (rptdocument)
    CrystalReportViewer1.ShowRefreshButton = True
    CrystalReportViewer1.ShowRefreshButton = False
    CrystalReportViewer1.ShowPrintButton = True
    CrystalReportViewer1.DisplayGroupTree = FalseEndSub

That is the entire project, nothing else, im sure its something silly i missed. Any ideas?

Thank you!


Am I able to use the above tools in the Title bar on a 64-bit Windows Vista/7 machine.  My setup/deployment exe is currently set to 'AnyCPU' as far as the compile settings go.  I have a problem printing using Crystal Reports with this install with an error associated with 64-bit.

If I am able to use the above tools, do I recompile and set it to x86 or x64 to get it to work.  I'm in a world of hurt with this right now.

I manually installed the Crystal Reports 64-bit for .NET and the CrystalReportView will display but when you click on it nothing happens.


Hi all,


I developed an application on vb.net 2003 and I have few reports developed using crystal reports 8.5 and embedded on the application.  Now I upgraded reports using Crystal reports XI.  I could embed the reports successfully on the developer machine but where as when I install the application on the other client machine I get an error which says


The located assembly's manifest definition with name 'CrystalDecisions.Windows.Forms' does not match the assembly reference.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: The located assembly's manifest definition with name 'CrystalDecisions.Windows.Forms' does not match the assembly reference.

File name: "CrystalDecisions.Windows.Forms"

   at IMPEX.frmEmpProfile.InitializeComponent()

   at IMPEX.frmEmpProfile..ctor()


=== Pre-bind state information ===

LOG: DisplayName = CrystalDecisions.Windows.Forms, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304


LOG: Appbase = C:\Program Files\IMPEX\IMPEX SETUP\

LOG: Initial PrivatePath = NULL

Calling assembly : IMPEX, Version=, Culture=neutral, PublicKeyToken=null.



LOG: Publisher policy file is not found.

LOG: Host configuration file not found.

LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config.

LOG: Post-policy reference: CrystalDecisions.Windows.Forms, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304

LOG: Attempting download of new URL file:///C:/Program Files/IMPEX/IMPEX SETUP/CrystalDecisions.Windows.Forms.DLL.

WRN: Comparing the assembly name resulted in the mismatch: Major Version


I run Vs2003 and vs2008 in parallel.  


can anyone help me in this regard.


I've a window application that load crystal report perfectly fine on Windows Vista. But when I tried to run the application on Windows 7, it gives me inconsistent behavior: sometimes the report will load, sometime I will just see the blue wheel, sometime it gives report load failed exception.

My application was developed with VS 2005 with Framework 2.0 and CR 10.
My Windows vista is install with framework 2.0, 3.0 and 3.5. 
Windows 7 is also came with 2.0, 3.0 and 3.5 by default.

I do notice one difference between Windows 7 and Vista. 
When a call is made to the report, a temp rpt is created in C:\Users\<user>\AppData\Local\Temp folder.
In Vista, no matter how many times the report is called in a session, only 1 rpt file will be created.
In Win 7, every call to the report will created 1 rpt file.
This is the only difference I see so far. Could this be the cause of report load failure? 
If so, what's the workaround?

An extract of my code as follow:

Dim crReportDocument As New ReportDocument()


crReportDocument.Load("C:\reports\myreport.rpt", OpenReportMethod.OpenReportByTempCopy)


If Not CrystalReportViewer1.ReportSource Is Nothing Then      



CrystalReportViewer1.ReportSource = Nothing

End If


CrystalReportViewer1.ReportSource = crReportDocument

'CrystalReportViewer1 is public



During  install VB.net I check Crystal report but I can't Use crystal report, I don't Know what I must do to solve it

I have moved a system i am writing from VB.NET 2005 with CR 11 to VB.NET 2008 with CR 2008.  The move seems to have gone fine apart from the recordselectionformula.  It just doesn't do anything, its almost as though the report ignores it.  The right values go into it but it has no effect on the report.  The line of code is as follows:
crreportdocument.DataDefinition.RecordSelectionFormula = "{errorlog.updatedby}=" & "'" & cboUser.Text & "'" & " and {errorlog.version}>=" & "'" & cboStartVersion.Text & "'"
I have made sure the report and the viewer are both from CR2008 but for some reason it just doesn't work. 

Anyone any ideas?

I have an asp.net application with requirment print pdf from webform with database operation using itext. So i want to handl the pdf print as dynamicaly. So i am decided to  create 4 pdf . one for master Data bind with first pdf. Second for subform data(One Disease form) and 3rd and forth also same as second form for another disease information..    So when the user will choose the disease selection using the checkbox. Based up on that selection i want to print the data how the it comes  to webform same i want to print in pdf when click on the print buttton . So i decided to impliment my logic that is for examble when a user submit the data with master entry field in a panel after that he selected check box with subfrm 2nd and 4 th out 4 check box then panel  with sub form 2nd and 4 th  will be coming there then submit. Then again user go to seach based up on the id  and bring the records from table then disply it on webform. After that user go to click on the print button. I already created 5 seperate pdf file with template (checkbox ,radio button,texbox all those things are in pdf already for each). So firat master pdf for all if there any check box selection came. Then take 2nd pdf and 4th from the directory then bind data. Later on i want to merge it as single one (single pdf). First page will be master data then next page 2nd subform  then 3rd page for 4th subform. after merge this one bring it another directrory(Merged copy with our id as file name stored here then take it for print) and print that .

So i kindly asking my logic is simple or complicated idea. if there any simple this available for dynamic pdf handling. Plz send the detals and url  with souce code.

If possible develop one simple application with same requirment and send it me.

Also i need the code help for it.

I worrying abt it how to handle this one


Hi I am facing a problem that I could not export the reports in excel 2007-2010 format from crystal report, please help me out if there is any service pack or new version is available to fix this prob.

<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure