I have recently started using Rotativa and it's amazing, but today, i try to add a header to my pdf, it works without problems, but the header is rendered using the _layout.cshtml
and when I try to remove it using Layout = null
or rendering the header as PartialView
instead of View
it just show a empty page.
This is how i'm working
public ActionResult Print(string CodigoDelfos, int Revision, string Versiones)
{
//Create the url for the header (Test action)
UriBuilder u = new UriBuilder(Request.Url.AbsoluteUri)
{
Path = Url.Action("Test", "Home", null),
Query = null
};
//Format the header to read Test.cshtml file
string t = string.Format("--header-html {0}", u.Uri.ToString());
//The action i'll use to create the pdf
return new Rotativa.ActionAsPdf(nameof(ImprimirDetalleDistribucion), new
{
CodigoDelfos,
Revision,
Versiones
})
{
CustomSwitches = t
};
}
Then the Test.cshtml
file
<div class="container">
<img src="~/Content/Images/CabeceraGarantizados.jpg" class="img-fluid" />
</div>
Here it work fine if i render it as View()
(renders with deffault layout) but if i do it as PartialView()
the pdf result is blank
in the same way as if I use Layout = null
Why can this be happening?
Apparently Rotary needs the file to have the DOCTYPE
defined
The solution was just add DOCTYPE
Test.cshtml
@{ Layout = null; }
<!DOCTYPE html>
<div class="container">
<img src="~/Content/Images/CabeceraGarantizados.jpg" class="img-fluid" />
</div>