2

在我的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")" />

但它不起作用。我怎样才能做到这一点?如果有人知道请分享..

4

1 回答 1

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

查看其他图像类型的图像设备信息设置

于 2013-01-28T20:42:55.877 回答