HowTo: Embed a PDF file into an ASP.NET Panel?

I have a crystal report that I am currently exporting to PDF format and writting it to the window. This works great for displaying a single report, but I need to be able to display several reports. What I've got in mind is an AJAX TabControl, with one report on each Tab.

What I need help with is how to get my streamed PDF report to display inside of an ASP:Panel instead of in the entire page. Can anyone help me with this?

This is what I use to Stream the CrystalReport to PDF Format and display it...
Imports System.IO
Imports CrystalDecisions.Shared
 
    Protected Sub cmdPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
 
        Dim tmpReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim strFileName As String = Server.MapPath("~/Reports/Encroachment.rpt")
        tmpReport.Load(strFileName, OpenReportMethod.OpenReportByDefault)
 
        Dim oStream As New MemoryStream
        oStream = tmpReport.ExportToStream(ExportFormatType.PortableDocFormat)
 
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/pdf"
        Response.BinaryWrite(oStream.ToArray)
        Response.End()
 
    End Sub

Open in new window

LVL 1
AaronNanceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gnoonCommented:
Within a ASP:Panel, you can add an iframe to display a report. The iframe points to the a report's generation script. You might create the script which generates report, as your code above, in Page_Load sub upon reportname sent via parameter.

<html>
<body>
<asp:Panel id="Panel1" Runat="Server" ... >
    <iframe id="acrobatPanel" src="reportGenerator.aspx?reportname=Report1" width="100%" height="100%" frameborder=0></iframe>
</asp:Panel>
<asp:Panel id="Panel2" Runat="Server" ... >
    <iframe id="acrobatPanel" src="reportGenerator.aspx?reportname=Report2" width="100%" height="100%" frameborder=0></iframe>
</asp:Panel>
</body>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim tmpReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim strFileName As String = Server.MapPath("~/Reports/" & Request("reportname") & ".rpt")
        tmpReport.Load(strFileName, OpenReportMethod.OpenReportByDefault)
 
        Dim oStream As New MemoryStream
        oStream = tmpReport.ExportToStream(ExportFormatType.PortableDocFormat)
 
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/pdf"
        Response.BinaryWrite(oStream.ToArray)
        Response.End()
 
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AaronNanceAuthor Commented:
This works great!


But, what if I don't know the ReportName until runtime (PageLoad)?
0
gnoonCommented:
No problem, you dont need to provide reportname from the url. You can read it from database or random one from a list, but just provide reportname for tmpReport.Load() for each request.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.