2012-03-29 95 views
0

我在.NET 2.0 asp.net網站中使用水晶報表來創建報表中的PDF。然後我想把這個報告傳輸到瀏覽器,我已經知道該怎麼做。我不知道該怎麼做的是定位將保存PDF的對象標籤。有人知道如何使用JavaScript或其他方式在HTML中執行此操作嗎?HTML頁面中帶有PDF流的目標對象標籤

在此先感謝您提供的任何幫助。

回答

1

我想回來後,找出我必須做的事情後回答。我不得不創建一個單獨的aspx頁面並將其稱爲PDFView.aspx。然後我添加的代碼到pageLoad的事件:

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(); 

    } 

我創建的報表對象設置的所有參數和數據源在調用aspx頁面和寫報告到一個會話變量進行檢索時,PDFView.aspx頁面加載。然後,我使用上面的代碼來檢索,執行並將報告作爲二進制流「二進制PDF」流式傳輸到瀏覽器響應流。

的PDFView.aspx頁面中調用頁面引用一個對象標籤是這樣的:

<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>