Click here to Skip to main content
Click here to Skip to main content

Generate a PDF document from exported stream of a crystal report

By , 10 May 2010
 
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)

About the Author

lidialee
Unknown
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalwhat is the refrence for Imports QuoteManagermemberahmedshamsshalaby16 Dec '11 - 7:19 
what is the refrence for Imports QuoteManager

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 10 May 2010
Article Copyright 2010 by lidialee
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid