I am making a PDF where I wanted to remove the links in the PDF using rotativa. But as I executed it, the links still shows and its buttons.
I already used the function:
CustomSwitches = "--print-media-type
and made a CSS of:
@media print {
.no-print, .no-print * {
display: none !important;
}
}
but still, it would not work, only the navbar is being deleted in the PDF.
Does anyone know what I could do to fix this problem?
CodePudding user response:
Please, check if this code works for you:
Action for controller (in my case HomeController.cs):
[HttpPost]
public ActionResult PrintWithoutLinks()
{
string customSwitches = "--print-media-type";
return new ViewAsPdf("Index")
{
FileName = "TestRotativaNoLinks.pdf",
CustomSwitches = customSwitches
};
}
View (in my case Index.cshtml):
@using (Html.BeginForm("PrintWithoutLinks", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div >
<h1>TEST classes</h1>
<p >Generate PDF without links</p>
<p><a href="#" target="_blank"><input type="submit" value="Generate PDF" /></a></p>
</div>
}
CSS (exactly the same you provided, in my case Site.css):
@media print {
.no-print, .no-print * {
display: none !important;
}
}