【发布时间】:2021-11-01 10:46:30
【问题描述】:
我在 Asp.Net MVC 应用程序中使用 Rotativa 为 单一发票 生成单一 PDF 文件。我正在使用命令 --header-html 和 ViewAsPdf 的 CustomSwitches 来包含发票每个页面的标题,如下所示,
public ActionResult GenerateSingleInvoicePDF(string invoiceId)
{
var invoiceViewModel = new InvoicePDFModel();
... // get content from database;
...
...
ViewBag.InvoiceDetail = invoiceViewModel;
string customSwitches = string.Format("--print-media-type --allow {0} --header-html {0} --page-offset \"0\" --header-spacing \"1\" ", Url.Action("InvoiceHeader", "Order", new { invNumber =
invoiceViewModel.invNo, invDate = invoiceViewModel.InvoiceDateString, shippAddr = invoiceViewModel.DeliveryAddr, billingAddress = invoiceViewModel.BillingAddr }, "http"));
return new ViewAsPdf("~/SingleInvoiceView.cshtml")
{
FileName = "SingleInvoice.pdf",
PageSize = Size.A4,
CustomSwitches = customSwitches
};
}
这完全没有问题。现在我需要的是如何为多张发票生成一个PDF。我为多张发票尝试了上面的代码,如下所示,
public ActionResult GenerateMultipleInvoicePDF(string invoiceIds)
{
var invoiceList = new List<InvoicePDFModel>
... // get list of content from database;
...
...
ViewBag.InvoiceList = invoiceList;
string customSwitches = // don't know how to define header view for multiple invoice.
return new ViewAsPdf("~/MultiInvoiceView.cshtml")
{
FileName = "MultiInvoice.pdf",
PageSize = Size.A4,
CustomSwitches = customSwitches
};
}
但我被困在标题部分。因为,每个发票的标题内容都不同。有什么建议如何做到这一点?
【问题讨论】:
-
我的要求是,在单个 PDF 文档中,我需要为发票一一生成 PDF 页面。例如,发票 1、发票 2 等等。每张发票同时具有不同的抬头内容。