我和Rotativa有点问题。我打印表,我想在每个打印的页面上都有页眉和页脚。问题是,有时它能工作,有时不能,即使pdf不包含头文件,它仍然和带有头文件的pdf文件大小相同。有什么解决方案吗?:/下面是我生成pdf的方法
string footer = this.Url.Action("PDFGeneratorFooter", "Home", null, this.Request.Url.Scheme);
string header = this.Url.Action("PDFGeneratorHeader", "Home", new { number = number }, this.Request.Url.Scheme);
var pdfFile = new Rotativa.ViewAsPdf("OffersToPdf", movm)
{
PageSize = Rotativa.Options.Size.A4,
FileName = "firstPdf.pdf",
CustomSwitches = " --footer-html \"" + footer + "\" " + "--header-html \"" + header + "\""
};
byte[] applicationPDFData = pdfFile.BuildPdf(ControllerContext);
path = Path.Combine(path, pdfFile.FileName);
var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
fileStream.Write(applicationPDFData, 0, applicationPDFData.Length);
fileStream.Close();这是我的标题视图
<body style="margin:0 !important; padding:0 !important;">
@{
Layout = null;
}
<div class="col-xs-12" style="background-color: black;">
<img src="~/Content/Images/logo.png">
</div>
</body>发布于 2018-12-29 03:07:38
我也有同样的问题。不能将页眉/页脚文件设置为普通的.html,因为您希望能够将模型传递给视图。
下面是你可以做的一些对我有用的事情:
--javascript-delay 400 (默认值为200ms)。<!DOCTYPE html>标记放在每个文件的最顶部,包括包含内容的文件,在本例中是您的OffersToPdf文件。此外,使用Rotativa PageMargins选项,以便在PDF上有足够的空间来容纳页眉和页脚。
var pdfFile = new Rotativa.ViewAsPdf("OffersToPdf", movm)
{
PageSize = Rotativa.Options.Size.A4,
FileName = "firstPdf.pdf",
PageMargins = new Rotativa.Options.Margins(25, 5, 35, 5)
CustomSwitches = " --footer-html \"" + footer + "\" " + "--header-html \"" + header + "\""
};发布于 2017-07-20 03:05:21
我不认为你还需要这个但不管怎样..。由于您没有任何布局,因此标题没有html格式。并且您需要设置DOCTYPE ()。更好的方法是给出一个普通的.html文件作为头文件。我给你这个我找到的链接作为例子:Add footer and header to pdf in rotativa
发布于 2018-09-06 20:43:02
我在使用.cshtml文件的页脚旁边的页眉时也遇到了问题,我只能使用页眉或页脚,直到我通过html将两者都更改。
在这种情况下,使用两个扩展名为.html的文件。
https://stackoverflow.com/questions/38722580
复制相似问题