Javascript 在Asp MVC 5中使用Rotativa PDF生成器隐藏PDF中的打印按钮和导航菜单
我想将页面内容转换为PDF格式。因此,我安装了nuget package rotativa,当我尝试打印视图时,它会以PDF格式显示整个页面以及打印按钮。我不想在我想要的输出PDF中显示打印按钮和导航菜单Javascript 在Asp MVC 5中使用Rotativa PDF生成器隐藏PDF中的打印按钮和导航菜单,javascript,c#,jquery,asp.net-mvc,rotativa,Javascript,C#,Jquery,Asp.net Mvc,Rotativa,我想将页面内容转换为PDF格式。因此,我安装了nuget package rotativa,当我尝试打印视图时,它会以PDF格式显示整个页面以及打印按钮。我不想在我想要的输出PDF中显示打印按钮和导航菜单 为了实现这一点,我创建了新的视图(Preview.cshtml),其中包含需要导出为PDF格式的数据 public ActionResult ExportCvPdf() { string switches = string.Format("--disable-smart-shrinki
为了实现这一点,我创建了新的视图(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);
}
为了实现这一点,我创建了新的视图(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);
}
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",
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
};
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",
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
};