Creating a PDF from a crystal report at runtime

The code sample below shows how to create a pdf during runtime from any crystal report. This code assumes you already have a valid report ‘myreport’, if you want an example of how to create a report item from code check

' --- export report to pdf
  
'Imports CrystalDecisions.CrystalReports.Engine
'Imports CrystalDecisions.Shared
  
Dim s_filename As String        ' name of the file
Dim s_serverpath As String      ' path to store the file
Dim exportoptions As ExportOptions
Dim diskfileoptions As New DiskFileDestinationOptions
s_serverpath = "\\some\server\path\"
s_filename = "somefile.pdf"
  
File.Delete(s_serverpath & s_filename)                               ' delete old export if it exists
diskfileoptions.DiskFileName = s_serverpath & s_filename
exportoptions = myreport.ExportOptions                               ' get handle to the report options
exportoptions.ExportDestinationType = ExportDestinationType.DiskFile ' set target to disk
exportoptions.ExportFormatType = ExportFormatType.PortableDocFormat  ' set pdf type
exportoptions.ExportDestinationOptions = diskfileoptions             ' pass handle to the filename
myreport.Expor