在ASP.net MVC3(Razor)中将rdlc转换为图像

时间:2013-01-28 07:04:47

标签: asp.net-mvc asp.net-mvc-3 image razor rdlc

在我的asp.net mvc3(Razor)应用程序中,我使用rdlc进行报告。出于打印目的,我只是need to convert the rdlc into image。我刚试过以下代码

   public ActionResult FilePrint()
    {
        LocalReport localReport = new LocalReport();

        localReport.ReportPath = @"Reports/OP/Rdlc/ClinicInvoiceReceipt.rdlc";

        iClinicInvoiceReceipt = new RmtOPInvoice.ClinicInvoiceReceipt();
        DataTable dt = iClinicInvoiceReceipt.SelectReceiptDtlForPrint(2);

        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Value = dt;
        reportDataSource.Name = "DataSet1";
        localReport.DataSources.Add(reportDataSource);

        string reportType = "Image";
        string mimeType;
        string encoding;
        string fileNameExtension;
        Warning[] warnings;

        string[] streams;

        byte[] renderedBytes;
        //Render the report

        renderedBytes = localReport.Render(
            reportType,
            null,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

        return File(renderedBytes, "Image");
  }

并在视野中

 <img src="@Url.Action("FilePrint","ClinicInvoiceReceipt")" />

但它不起作用。我怎样才能实现这一目标?如果有人知道请分享..

1 个答案:

答案 0 :(得分:4)

您缺少DeviceInfo设置。按如下所示创建DeviceInfo设置

 string deviceInfo =
        "<DeviceInfo>" +
        "  <OutputFormat>JPEG</OutputFormat>" +
        "  <PageWidth>8.5in</PageWidth>" +
        "  <PageHeight>11in</PageHeight>" +
        "  <MarginTop>0.4in</MarginTop>" +
        "  <MarginLeft>0.6in</MarginLeft>" +
        "  <MarginRight>0.6in</MarginRight>" +
        "  <MarginBottom>0.4in</MarginBottom>" +
        "</DeviceInfo>";

并更改

renderedBytes = localReport.Render(
        reportType,
        null,
        out mimeType,
        out encoding,
        out fileNameExtension,
        out streams,
        out warnings);

return File(renderedBytes, "Image");

renderedBytes = localReport.Render(
        reportType,
        deviceInfo ,
        out mimeType,
        out encoding,
        out fileNameExtension,
        out streams,
        out warnings);

return File(renderedBytes, "image/jpeg");

查看其他图像类型的Image Device Information Settings