【问题标题】:Rotativa Display HTML header and footerRotativa 显示 HTML 页眉和页脚
【发布时间】:2017-11-30 07:48:43
【问题描述】:

我最近开始使用 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}\",则页脚显示得非常好。问题是我需要同时显示页眉和页脚。

任何帮助将不胜感激。

【问题讨论】:

    标签: c# asp.net-mvc rotativa


    【解决方案1】:

    对我来说,它只有在将页眉和页脚保留为 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")}\""
                };
    

    【讨论】:

    • model.ToPagedList的目的是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    相关资源
    最近更新 更多