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

, 10 May 2010
Rate this:
Please Sign up or sign in to vote.
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)

About the Author

lidialee

Unknown
No Biography provided

Comments and Discussions

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

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 10 May 2010
Article Copyright 2010 by lidialee
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid