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