Rotativa显示HTML页眉和页脚

时间:2017-06-27 09:49:02

标签: c# asp.net-mvc rotativa

我最近开始使用Rotativa,效果很好!除了尝试配置PDF文档的页眉和页脚。

string customSwitches = string.Format("--header-html \"{4}\" --footer-left \"{0} {1} - {2}\" --footer-center \"{3}\" --footer-right \"Page: [page]/[toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 6", "Billing Report", FromDate.Value.ToString("yyyy-MM-dd"), ToDate.Value.ToString("yyyy-MM-dd"), customerData.Name, Url.Action("BillingRunHeader", "Report", new { area = "Admin" }, "http"));
var actionResult = new ViewAsPdf("_BillingRunPDF", GetBillingReport(UserFilterReport, ProductFilterReport, ProjectFilterReport, CustomerFilterReport.Where(x => x == customer).ToArray(), TypeFilterReport, ReportType, FromDate, ToDate, Billable, TaskId).ToList())
{
     PageSize = Size.A4,
     PageOrientation = Orientation.Landscape,
     FileName = customerData.Name.Replace(" ","_") + "_Billing_Report_" + DateTime.Now.Date.ToString("yyyy-MM-dd") + ".pdf",
     CustomSwitches = customSwitches
};

上面我创建了一个字符串格式,用数据替换某些占位符。 --header-html \"{4}\"是从存储的View模板中提取的,该模板包含标题的图像,并且显示完美。问题是页脚根本不显示。

如果我删除--header-html \"{4}\",则页脚显示完全正常。问题是我需要显示页眉和页脚。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

对我来说,它仅在将页眉和页脚留给HTML之后才起作用。

return new ViewAsPdf
            {
                ViewName = "RptVistoriador",
                PageSize = Rotativa.Options.Size.A4,
                Model = lstVistoriadorRptViewModel.ToPagedList(1, lstVistoriadorRptViewModel.Count()),                    
                CustomSwitches = $"--footer-html \"{Url.Action("ReportHeader", "Vistoriador", new { area = "" }, "http")}\" --header-html \"{Url.Action("ReportHeader", "Vistoriador", new { area = "" }, "http")}\""
            };