从 MVC 3 控制器将 JavaScript 注入到 PDF
本文关键字:注入 PDF JavaScript MVC 控制器 | 更新日期: 2023-09-27 17:56:53
在我的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上。但是我对在上面的代码中实现这一点感到困惑。如果有人经历过这个,请分享.这对我真的很有帮助。
我刚刚发现在 PHP 中完成了相同的场景。这里。
也许我找到的这个答案很有帮助
- 它是 ASP.NET MVC
- 它直接流式传输 RDLC 响应
http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx
我使用 iTextSharp
这是我做的示例项目。