Question

I am using crystal reports in a .NET 2.0 asp.net website to create a PDF from the report. I then want to stream the report to the browser, which I already know how to do. What I don't know how to do is target the object tag the will hold the PDF. Does someone know how to do this within HTML with javascript or any other way?

Thanks in advance for any help that can be given.

Was it helpful?

Solution

I wanted to come back and answer this after finding out what I had to do. I had to create a separate aspx page and called it PDFView.aspx. I then added the code to the PageLoad event:

if (!IsPostBack)
     {
        ReportDocument rpt;
        rpt = (ReportDocument)Session["CrystalReport"];
        System.IO.Stream myStream;

        CrystalDecisions.Shared.ExportOptions myExportOptions;
        myExportOptions = myReport.ExportOptions;
        myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
        myExportOptions.FormatOptions = new CrystalDecisions.Shared.PdfRtfWordFormatOptions();

        CrystalDecisions.Shared.ExportRequestContext myExportRequestContext = new CrystalDecisions.Shared.ExportRequestContext();
        myExportRequestContext.ExportInfo = myExportOptions;
        //SetReportParameter("pPrinterFriendly", true, (ReportClass)myReport);

        System.Web.HttpContext.Current.Response.ClearContent();
        System.Web.HttpContext.Current.Response.ClearHeaders();
        System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
        myStream = myReport.FormatEngine.ExportToStream(myExportRequestContext);
        Byte[] myBuffer = new Byte[myStream.Length];
        myStream.Read(myBuffer, 0, (int)myStream.Length);
        System.Web.HttpContext.Current.Response.BinaryWrite(myBuffer);
        System.Web.HttpContext.Current.Response.Flush();

     }

I created the report object setting all parameters and datasource in the calling aspx page and the wrote the report to a session variable for retrieval when the PDFView.aspx page is loaded. I then used the code above to retrieve, execute and stream the report as a binary stream "the binary PDF" to the browsers response stream.

The PDFView.aspx page is referenced in the calling page with an object tag like this:

<object id="pdfObj" type="application/pdf" style="width:60%;height:95%;position:relative;top:2%;left:0%;right:10%;bottom:10%;margin:0px;padding:0px;border:0px;" data="PDFView.aspx"></object>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top