【问题标题】:Injecting JavaScript to PDF from MVC 3 controller从 MVC 3 控制器将 JavaScript 注入 PDF
【发布时间】:2013-01-16 16:19:13
【问题描述】:

在我的ASP.NET MVC3(Razor) 应用程序中,我正在为print utility 苦苦挣扎。我要auto print a PDF file which is converted from rdlc

我使用以下代码将 rdlc 转换为 pdf:

        LocalReport localReport = new LocalReport();

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

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

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

        string reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;

        string deviceInfo =
         @"<DeviceInfo>
            <OutputFormat>PDF</OutputFormat>
            <PageWidth>5.83in</PageWidth>
            <PageHeight>8.27in</PageHeight>
            <MarginTop>0in</MarginTop>
            <MarginLeft>0.in</MarginLeft>
            <MarginRight>0in</MarginRight>
            <MarginBottom>in</MarginBottom>
        </DeviceInfo>";
        Warning[] warnings;

        string[] streams;

        byte[] renderedBytes;

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

        return File(renderedBytes, "application/pdf");

我想在视图上显示这个同时想open the print dialog of pdf viewer automaticaly

我只是在这里将 javscript 转换为 pdf here。但是我对在我上面的代码中实现这一点感到困惑。如果有人经历过这个,请分享。这对我真的很有帮助。

我刚刚发现在 PHP 中完成了相同的场景。 Here.

【问题讨论】:

  • 您对网络浏览器(或 PDF 插件)的运行方式没有太多控制权。
  • 该引用是 Acrobat 特定的实现 - 这被视为安全风险。

标签: c# javascript asp.net-mvc-3 pdf-generation acrobat-sdk


【解决方案1】:

也许我发现的这个答案很有帮助

  1. 是 ASP.NET MVC
  2. 直接流式传输 RDLC 响应

http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx

【讨论】:

    【解决方案2】:

    我使用iTextSharp实现了这一点

    Here 是我做的示例项目。

    【讨论】:

    • 为什么要投票。我已经准备好证明...请评论有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多