Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我是否可以从SQL Reporting Services(.rdlc)生成基于图像的PDF报告,而不将图像保存在任何位置?_C#_Sql Server_Pdf Generation_Ssrs 2008 - Fatal编程技术网

C# 我是否可以从SQL Reporting Services(.rdlc)生成基于图像的PDF报告,而不将图像保存在任何位置?

C# 我是否可以从SQL Reporting Services(.rdlc)生成基于图像的PDF报告,而不将图像保存在任何位置?,c#,sql-server,pdf-generation,ssrs-2008,C#,Sql Server,Pdf Generation,Ssrs 2008,情景: 我有一个包含多个图表的网页,我有一个“导出为PDF”按钮,用户可以点击该按钮,它生成一个PDF,然后用户可以保存 鉴于: 一种Telerik雷达图,可将自身保存到内存流中,如下所示: MemoryStream chartStream = new MemoryStream(); RadChart1.Save(chartStream, ImageFormat.Png); 使用此内存流,是否可以使用SQL Reporting Services构建PDF,而不首先将其保存到文件或必须首先将其插

情景:

我有一个包含多个图表的网页,我有一个“导出为PDF”按钮,用户可以点击该按钮,它生成一个PDF,然后用户可以保存

鉴于:

一种Telerik雷达图,可将自身保存到内存流中,如下所示:

MemoryStream chartStream = new MemoryStream();
RadChart1.Save(chartStream, ImageFormat.Png);
使用此内存流,是否可以使用SQL Reporting Services构建PDF,而不首先将其保存到文件或必须首先将其插入MSSQL表

我也会投票和/或接受任何开源或免费解决这个问题的答案


谢谢

我过去使用的方法没有问题,对我来说非常有效。

我过去使用的方法没有问题,对我来说非常有效。

我使用iTextSharp生成所有PDF。有一点学习的曲线,但它变得很容易。以下是一些链接:


我使用iTextSharp生成所有PDF。有一点学习的曲线,但它变得很容易。以下是一些链接:


好吧,我刚想好。这个答案有三个要素,两个屏幕截图按顺序排列,然后是一些代码:

创建类型化数据集以保存图表图像

将类型化数据集连接到RDLC报告

用于生成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();

}

好吧,我刚想好。这个答案有三个要素,两个屏幕截图按顺序排列,然后是一些代码:

创建类型化数据集以保存图表图像

将类型化数据集连接到RDLC报告

用于生成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();

}

你能在代码中使用PrintDocument类对一个正在运行的pdf编写器进行修改吗?@Paul,好主意,但这行不通,因为我们有多个图表以及一些其他变量数据。我需要使用reporting services构建一个PDF,我认为这会迫使我将所有图表保存为图像,或者将它们保存在数据库表或另一个PDF生成器中。你能在运行中使用PrintDocument类对PDF编写器进行编码吗?@Paul,好主意,但这行不通,因为我们有多个图表和一些其他变量数据。我需要使用reporting services构建PDF,我认为这会迫使我将所有图表保存为图像,或者将它们保存在数据库表或其他PDF生成器中。谢谢,但这是我呈现PDF的方式,而不是在不使用数据库的情况下添加图像的方式+1无论如何,因为这仍然很有用。谢谢,但这是我呈现PDF的方式,而不是在不使用数据库的情况下添加图像的方式+1无论如何,因为这仍然有用。史诗!这正是我想要的。能够在内存中构建数据集,并将数据库全部传递:叙事诗这正是我想要的。能够在内存中构建数据集,并将数据库全部传递: