Click here to Skip to main content
15,884,176 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Generate a PDF document from exported stream of a crystal report

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
10 May 2010CPOL 19K   2   1
I have a report which can be viewed in Crystal Report viewer in VS. Client needs to generate a PDF file with a click of a button and the PDF should pop up upon finishing exporting and let the client decide where to save the file.'vb.netImports...
I have a report which can be viewed in Crystal Report viewer in VS. Client needs to generate a PDF file with a click of a button and the PDF should pop up upon finishing exporting and let the client decide where to save the file.

'vb.net
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Imports QuoteManager
Imports System.Web
Public Class frmQuoteRptPreview
    Private objRpt As rptQuotation

    Public Overloads Sub ShowDialog(ByVal objQuoteH As DataTable, ByVal objQuoteD As DataTable, ByVal strService As String, ByVal strSales As String, _
                                    ByVal strQuotedBy As String, ByVal strQuoteRef As String, ByVal parent As IWin32Window)
        Dim objDataset As New DataSet
        objDataset.Tables.Add(objQuoteH.Copy())
        objDataset.Tables.Add(objQuoteD.Copy())
        objDataset.Relations.Add("MD", objDataset.Tables(0).Columns("RecID"), objDataset.Tables(1).Columns("QuoteID"))
        objRpt = New rptQuotation
        objRpt.SetDataSource(objDataset)
        objRpt.SetParameterValue(0, strService)
        objRpt.SetParameterValue(1, strQuotedBy)
        objRpt.SetParameterValue(2, strSales)
        objRpt.SetParameterValue(3, strQuoteRef)
        crvQuotes.ReportSource = objRpt
        ' Show the dialog
        Me.ShowDialog(parent)
    End Sub
    Private Sub msExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msExit.Click
        Me.Close()
    End Sub
    Private Sub msGPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msGPDF.Click

        Dim s As System.IO.MemoryStream = objRpt.ExportToStream(ExportFormatType.PortableDocFormat)
        Dim fs As System.IO.FileStream
        Dim w As System.IO.BinaryWriter
        'will generate in the app foot folder
        fs = New System.IO.FileStream("Report.pdf", IO.FileMode.OpenOrCreate)
        w = New System.IO.BinaryWriter(fs)
        w.Seek(0, System.IO.SeekOrigin.Begin)
        w.Write(s.ToArray)
        w.Close()
        fs.Close()
        System.Diagnostics.Process.Start(fs.Name)

    End Sub
End Class


Hope this is helpful.

License

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


Written By
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalwhat is the refrence for Imports QuoteManager Pin
ahmedshamsshalaby16-Dec-11 7:19
ahmedshamsshalaby16-Dec-11 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.