asp.net-mvc – 在MVC中使用Rotativa pdf显示动态标头
发布时间:2020-12-16 03:45:37 所属栏目:asp.Net 来源:网络整理
导读:我想打印动态的标题数据,它将来自控制器. 那么如何使用Rotativa pdf在标题中显示动态数据. 我的标题数据包括名称,地址,联系信息和其他附加信息,这些信息是动态的,并从控制器端生成. 我使用html页面创建了带有静态头的pdf,如下所示 string header = Server.Ma
我想打印动态的标题数据,它将来自控制器.
那么如何使用Rotativa pdf在标题中显示动态数据. 我的标题数据包括名称,地址,联系信息和其他附加信息,这些信息是动态的,并从控制器端生成. 我使用html页面创建了带有静态头的pdf,如下所示 string header = Server.MapPath("~/Static/NewFolder/PrintHeader.html"); string footer = Server.MapPath("~/Static/NewFolder/PrintFooter.html"); string customSwitches = string.Format("--header-html "{0}" " + "--header-spacing "0" " + "--footer-html "{1}" " + "--footer-spacing "10" " + "--footer-font-size "10" " + "--header-font-size "10" ",header,footer); return new ViewAsPdf("SchedulePrintPdf",modelData) { CustomSwitches = customSwitches,PageOrientation = Orientation.Portrait,PageMargins = { Top = 20,Bottom = 22 },SaveOnServerPath = filePath,FileName = Path.GetFileName(fileName) }; 这适用于Static标头. 现在我需要动态地从这个控制器发送标题文本. 解决方法
我有一个类似的规范,并通过额外的打印视图实现它.
在那里,您可以从控制器获取其他数据,并包含一种特殊的CSS样式. 在我的情况下,Print-View被称为ResultPrint.cshtml,在Controller中我有这个功能: public ActionResult GeneratePDF(int id) { InputPrintModel model = db.InputPrintModel.Find(id); if (model == null) { return HttpNotFound(); } try { return new ViewAsPdf("ResultPrint",model); } catch (Exception ex) { // Error Dialog + Logging return View("Result",model); } } 这在我的Result.cshtml中被调用,如下所示: @Html.ActionLink("Generate PDF","GeneratePDF",new { id = Model.Id }) 编辑 当您查看此答案https://stackoverflow.com/a/26544977/2660864时,您可以看到,您可以在CustomActions中使用.cshtml文件(我没有测试此代码) public ActionResult ViewPDF() { string cusomtSwitches = string.Format("--print-media-type --allow {0} --footer-html {0} --footer-spacing -10",Url.Action("Footer","Document",new { area = ""},"https")); return new ViewAsPdf("MyPDF.cshtml",model) { FileName = "MyPDF.pdf",CustomSwitches = customSwitches }; } [AllowAnonymous] public ActionResult Footer() { // get custom data for view return View(model); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用.Resx文件获取全局应用程序消息?
- asp.net下文件上传和文件删除的代码
- 如何在非ASP.net上下文中使用C#中的数据验证属性?
- asp.netcore 自动挡Docker Nginx Redis(滴滴滴,自动挡)
- asp.net-mvc – Elmah基本设置问题/问题
- asp.net-mvc – 如何在发布MVC应用程序时包含自定义文件夹?
- ASP.NET MVC:如果url与当前url匹配,则将选定的CSS类添加到
- asp.net – 确定当前页面是否需要授权?
- asp.net-mvc – 如何使用绑定前缀?
- asp.net-mvc-3 – MVC3客户端验证无法使用Ajax.BeginForm表
推荐文章
站长推荐
- asp.net – 如何使用文件上传控件选择多个文件?
- 进程和线程
- asp.net-mvc – asp.mvc中渲染的区别是什么
- asp.net – 多个验证组,仅在控件模糊上验证一个
- asp.net – 如何使RequiredFieldValidator更改父
- asp.net-mvc – visual studio 2013“添加控制器
- asp.net-mvc – ASP.NET MVC DropDown编辑器模板
- 使用StateServer的ASP.NET会话混合(SCARY!)
- ASP.NET Webforms,用户控件中的JavaScript
- asp.net-mvc – aspnet_Profiles表中的PropertyV
热点阅读