Creating a PDF from a crystal report at runtime

Posted in: Crystal Reports
By dePoPo
Mar 11, 2009 - 11:33:33 AM


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 this link


        ' --- 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.Export()                                                    ' do the actual export


Visitor Comments