Click here to Skip to main content
Licence 
First Posted 23 Oct 2005
Views 33,957
Bookmarked 27 times

Reading RPT File Then Display Report as PDF

By | 23 Oct 2005 | Article
This Article Teach You How To Use External RPT File Rather Than Embedded RPT File (.DLL)
 
Part of The SQL Zone sponsored by
See Also

Introduction

When we develop a report for web application, the RPT file usually embedded into an DLL file. So when we want to edit the report, we must recompile the project. This is the simple solution for reading RPT file then displays it as PDF.

 

Now let’s creating a function to export and display your report into PDF.

 

    Private Function PrintDocument(ByVal SourceReport As Object, ByVal FormatType As CrystalDecisions.Shared.ExportFormatType, ByVal PaperSize As CrystalDecisions.Shared.PaperSize, ByVal PaperOrientation As CrystalDecisions.Shared.PaperOrientation)

        'Copyright IMAWA 2005 (Bluechip_Asia@yahoo.com)

        'For Educational Purpose Only

        'For Explanation of this function, see my previous article

        With SourceReport.FormatEngine.PrintOptions

            .PaperSize = PaperSize

            .PaperOrientation = PaperOrientation

        End With

        Dim st As System.IO.Stream

        Dim b() As Byte

        st = SourceReport.ExportToStream(FormatType)

        Page.Response.ClearHeaders()

        Page.Response.ContentType = "application/pdf"

        ReDim b(st.Length)

        st.Read(b, 0, CInt(st.Length))

        Page.Response.BinaryWrite(b)

        Page.Response.End()

    End Function

 

Next, we call the function when page loaded.

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Copyright IMAWA 2005 (Bluechip_Asia@yahoo.com)

        'For Educational Purpose Only

        'For Explanation of this function, see my previous article

        Dim myRpt As New ReportDocument

        myRpt.Site = Me.Site

        Try

            myRpt.Load(MapPath("../RPTFiles/Training.Rpt"))

            PrintDocument(myRpt, CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat, CrystalDecisions.[Shared].PaperSize.PaperLetter, CrystalDecisions.[Shared].PaperOrientation.Portrait)

        Catch ex As Exception

            Exit Sub

        End Try

    End Sub

 

 

The Complete Source code are :

 

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.ReportSource

Imports CrystalDecisions.Shared

 

Public Class ReportTraining

    Inherits System.Web.UI.Page

 

#Region " Web Form Designer Generated Code "

 

    'This call is required by the Web Form Designer.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

 

    End Sub

 

    'NOTE: The following placeholder declaration is required by the Web Form Designer.

    'Do not delete or move it.

    Private designerPlaceholderDeclaration As System.Object

 

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

        'CODEGEN: This method call is required by the Web Form Designer

        'Do not modify it using the code editor.

        InitializeComponent()

    End Sub

 

#End Region

 

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here

        Dim myRpt As New ReportDocument

        myRpt.Site = Me.Site

        Try

            myRpt.Load(Me.MapPath("../CPXPrint/Training.Rpt"))

            PrintDocument(myRpt, CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat, CrystalDecisions.[Shared].PaperSize.PaperLetter, CrystalDecisions.[Shared].PaperOrientation.Portrait)

        Catch ex As Exception

            Exit Sub

        End Try

    End Sub

 

    Private Function PrintDocument(ByVal SourceReport As Object, ByVal FormatType As CrystalDecisions.Shared.ExportFormatType, ByVal PaperSize As CrystalDecisions.Shared.PaperSize, ByVal PaperOrientation As CrystalDecisions.Shared.PaperOrientation)

        'Copyright IMAWA 2005 (Bluechip_Asia@yahoo.com)

        'For Educational Purpose Only

        'For Explanation of this function, see my previous article

        With SourceReport.FormatEngine.PrintOptions

            .PaperSize = PaperSize

            .PaperOrientation = PaperOrientation

        End With

        Dim st As System.IO.Stream

        Dim b() As Byte

        st = SourceReport.ExportToStream(FormatType)

        Page.Response.ClearHeaders()

        Page.Response.ContentType = "application/pdf"

        ReDim b(st.Length)

        st.Read(b, 0, CInt(st.Length))

        Page.Response.BinaryWrite(b)

        Page.Response.End()

    End Function

End Class

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

bluechip_asia

Web Developer

Indonesia Indonesia

Member



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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThread was being aborted Pinmembermarquito_cuba11:44 5 Jun '06  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 24 Oct 2005
Article Copyright 2005 by bluechip_asia
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid