Using Rotativa, a .net wrapper for wkhtmltopdf. I can not get CSS or Images to render in a PDF if I connect Via HTTPS. I have previously set this up on 2008r2 iis7 server with HTTPS(SSL) I did have simular trouble with css & webfonts, but I just changed all the paths to absolute paths and it worked.
This job is deployed on ii6 windows 2003 server. Yesterday it was just producing "An unhandled exception has occurred." when ussing HTTPS so I upgraded wkhtmltopdf to V 0.12.0, now the PDF will generate using ViewAsPdf, with no CSS or images. And using ActionAsPdf it renders a PDF of "You are not Authorised to view this page" error. But if I turn off HTTPS it renders as it should.
I added some test Action results, a view and a View Layout just to isolate the issue.
Im sure its not to do with the Absolute Path. Here are the 5 ways combinations of Absolute paths I tried in the header of the _TestCssFromPath.cshtml View Layout , they all work non HTTPS
_TestCssFromPath.cshtml:
@{string serverUrl = string.Format(@"{0}://{1}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority);}
<link href="@String.Format("{0}/Content/TestPdf.css",serverUrl )" rel="stylesheet" />
<link href="@serverUrl/Content/TestPdf.css" rel="stylesheet" />
@{
var path = VirtualPathUtility.ToAbsolute("~/Content/TestPdf.css");
var url = new Uri(Request.Url, path).AbsoluteUri;
}
<link href="@Href("~/Content/TestPdf.css")" rel="stylesheet" />
<link href="c:/serverPath/ToSite/Content/TestPdf.css" rel="stylesheet" />
<link href="c:\serverPath\ToSite\Content\TestPdf.css" rel="stylesheet" />
_TestInlineCss.cshtml: Just has the content off the css in the , and this does render CSS correctly, without Images or webfonts.
Home Controler:
public virtual ActionResult TestViewAsPdf(int id) {
if (id == 1) { ViewBag.Layout = "~/Views/Shared/_TestInlineCss.cshtml"; }
if (id == 2) { ViewBag.Layout = "~/Views/Shared/_TestCssFromPath.cshtml"; }
return new ViewAsPdf("PDF") { FileName = string.Format("test_PDF_{0}_{1:yyyyMMddHHmm}.pdf", id, DateTime.Now) };
}
public virtual ActionResult TestActionAsPdf(int id) {
return new ActionAsPdf("pdfView", new { id = id }) { FileName = string.Format("test_PDF2_{0}_{1:yyyyMMddHHmm}.pdf", id, DateTime.Now) };
}
public virtual ActionResult pdfView(int id) {
if (id == 1) { ViewBag.Layout = "~/Views/Shared/_TestInlineCss.cshtml"; }
if (id == 2) { ViewBag.Layout = "~/Views/Shared/_TestCssFromPath.cshtml"; }
return View("PDF");
}
PDF.cshtml
@{
ViewBag.Title = "PDF";
if (ViewBag.Layout != null) { Layout = ViewBag.Layout; }
}
<h2>PDF</h2>
Visiting the following URLs produces these results:
- /Home/TestViewAsPdf/1 ------> CSS works(as long as its already in the html), No Images
- /Home/TestViewAsPdf/2 ------> No CSS, No Images
- /Home/TestActionAsPdf/1 ----> PDF of "You are not Authorised to view this page"
- /Home/TestActionAsPdf/2 ----> PDF of "You are not Authorised to view this page"
I have gone through the folder permissions and they seam fine...What am I missing?
来源:https://stackoverflow.com/questions/23432973/rotativa-and-wkhtmltopdf-no-css-or-images-on-iis6-over-https-but-fine-on-http