答案 0 :(得分:1)
为实现这一目标,我创建了一个新视图(Preview.cshtml),其中包含我需要导出为PDF的数据。
public ActionResult ExportCvPdf()
{
string switches = string.Format("--disable-smart-shrinking --header-html {0} --footer-html {1}",
Url.Action("Header", "Cotroller", new { area = "Areaname" }, "http"),
Url.Action("Footer", "Cotroller", new { area = "Areaname" }, "http"));
return new Rotativa.ViewAsPdf("Preview", data)
{
FileName = "Sample-" + DateTime.Now.ToString("yyyyMMdd") + ".pdf",
PageSize = Size.A4,
PageMargins = new Margins(30, 15, 20, 15),
CustomSwitches = switches
};
}
public ActionResult Preview(ViewModel detail)
{
return View(detail);
}
答案 1 :(得分:0)
Rotativa不会渲染为打印介质,但是作为浏览器,您必须强制渲染为打印。
发送“ --print-media-type
”参数
这样做,您可以使用CSS隐藏要打印的介质
@media print
{
.no-print, .no-print *
{
display: none !important;
}
}
或使用引导程序隐藏印象
<input type="button" class="hidden-impression" value="PDF"/>
如何使旋转烤肉架了解如何打印 例如:
return new ViewAsPdf("Details", obj)
{
CustomSwitches = "--print-media-type"
}
完整示例:
return new ViewAsPdf("Details", obj)
{
CustomSwitches = "--print-media-type",
FileName = $"Talao_{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}.pdf",
PageOrientation = Orientation.Portrait,
PageSize = Size.A4,
PageMargins = new Margins(0, 0, 0, 0),
PageWidth = 210,
PageHeight = 297
};