簡體   English   中英

我可以從SQL Reporting Services(.rdlc)生成基於圖像的PDF報告,而無需將圖像保存到任何地方嗎?

[英]Can I generate an Image-based PDF report from SQL Reporting Services (.rdlc) with out saving the image anywhere?

場景:

我有一個包含多個圖表的網頁,並且有一個“導出為PDF”按鈕,用戶應該可以單擊該按鈕,然后生成一個PDF,然后可以將其保存。

鑒於:

可以將自身保存到內存流中的Telerik RadChart,如下所示:

MemoryStream chartStream = new MemoryStream();
RadChart1.Save(chartStream, ImageFormat.Png);

使用這種內存流,是有可能建立使用SQL Reporting Services的WITH OUT首先將其保存到文件必須首先插入到一個MSSQL表PDF?

我也將投票和/或接受任何答案,這些答案都是針對此問題的開源或免費解決方案。

謝謝。

好吧,只是想通了。 此答案包含三個元素,依次排列兩個屏幕截圖,然后添加一些代碼:

  1. 創建類型化的數據集以保存圖表圖像

    第1步

  2. 將類型化的數據集掛接到RDLC報告

    第2步

  3. 按鈕單擊代碼,用於生成PDF並將其流式傳輸到瀏覽器。

     protected void btnPDF_Click(object sender, EventArgs e) { //Put the image you want to display in a MemoryStream. You can read an image from the file system //or generate an image, etc. This example renders an image to a memory stream using a custom charting control. MemoryStream chtLoginsByMonthStream = new MemoryStream(); this.chtLoginsByMonth.Save(chtLoginsByMonthStream, ImageFormat.Png); //Setup the datatable you will pass into the RDLC dsStudentUsage.dtUsageChartsDataTable dt = new dsStudentUsage.dtUsageChartsDataTable(); dsStudentUsage.dtUsageChartsRow dr = dt.NewdtUsageChartsRow(); //create new Byte Array, this will hold the image data from the memory stream byte[] chtLoginsByMonthArray = new byte[chtLoginsByMonthStream.Length]; //Set pointer to the beginning of the stream chtLoginsByMonthStream.Position = 0; //Read the entire stream chtLoginsByMonthStream.Read(chtLoginsByMonthArray, 0, (int)chtLoginsByMonthStream.Length); //Put the byte array into the new datarow in the appropriate column dr["imgLoginsByMonth"] = chtLoginsByMonthArray; dt.Rows.Add(dr); //Add the data source to the report. ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsStudentUsage_dtUsageCharts", dt)); //Setup objects for streaming the PDF to the browser Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; byte[] bytes; //Make a container for all of your report parameters var rptList = new List<KeyValuePair<string, string>>(); rptList.Add(new KeyValuePair<string, string>("rpTotalLogins", "2,000")); //more parameters go here //Feed the report parameters into the actual "ReportParameters" class ReportParameter[] rptParams = new ReportParameter[rptList.Count]; for (int i = 0; i < rptList.Count; i++) { rptParams[i] = new ReportParameter(rptList[i].Key, rptList[i].Value); } //Set parameters for the report. ReportViewer1.LocalReport.SetParameters(rptParams); //Render the report to a byte array in PDF format bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings); //Set the stream to either prompt user as file download or "inline" to stream //PDF directly into the browser window. HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=StudentUsageReport.pdf"); //HttpContext.Current.Response.AddHeader("Content-disposition", "inline;"); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.BinaryWrite(bytes); HttpContext.Current.Response.End(); } 

過去,我一直沒有使用這種方法,對我來說效果很好。

我的所有PDF都使用iTextSharp。 有一些學習曲線,但是然后變得很容易。 這里是一些鏈接:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM