?
Solved

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

Posted on 2008-02-06
3
Medium Priority
?
5,253 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:AaronNance
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
gnoon earned 2000 total points
ID: 20837409
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
 
LVL 1

Author Comment

by:AaronNance
ID: 20841641
This works great!


But, what if I don't know the ReportName until runtime (PageLoad)?
0
 
LVL 16

Expert Comment

by:gnoon
ID: 20856030
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question