Click here to Skip to main content
16,020,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..
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
Posted

1 solution

The function below will do what you want, you'll need to adjust it a bit tho (had to translate some variables) and some things might not be needed for you (setting params / reconnecting ) but I'm sure you'll be able to adjust it to your needs.

VB
Public Shared Sub PrintToPDF(ByVal Reportname As String, ByVal params As List(Of ReportParameters), Optional ByVal path As String = "")
        Try
            Dim rpt As New ReportDocument
            If Reportnaam.EndsWith(".rpt") Then Reportnaam = Reportnaam.Replace(".rpt", "")
            Dim file As String = 'path to the report file
            If IO.File.Exists(file) = False Then
                'report could not be found
                Exit Sub
            End If
            rpt.Load(file)
            rpt = reconnectreport(rpt)
            If params IsNot Nothing AndAlso params.Count > 0 Then
                For Each c As ReportParameters In params
                    rpt.SetParameterValue(c.ParamNaam, c.ParamValue)
                Next
            End If
            If String.IsNullOrEmpty(path) Then
                Dim ofd As New SaveFileDialog
                ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
                ofd.Filter = ".pdf|PDF"
                If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Dim path As String = ofd.FileName
                    If path.EndsWith(".pdf") = False Then path &= ".pdf"
                    pad = path
                End If
            End If
            If Not String.IsNullOrEmpty(pad) Then
'exports the report to pdf
                rpt.ExportToDisk(ExportFormatType.PortableDocFormat, pad)
            End If
            'rpt.Dispose()
            'rpt = Nothing
        Catch ex As Exception
            JoroLogging.AddLog(ex, GetCurrentMethod.DeclaringType.Name, GetCurrentMethod.Name)
        End Try
    End Sub 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900