I have an MVC 4 project with Windows Authentication and I am using KendoUI to display charts and grids. As the data in the charts are loaded with Ajax I have to use the manual trigger. This is the code in my controller.
Code: C#
[HttpGet]
public ActionResult ExportToPdf()
{
WindowsIdentity winId = (WindowsIdentity)HttpContext.User.Identity;
WindowsImpersonationContext ctx = null;
var ms = new MemoryStream();
ctx = winId.Impersonate();
var doc = new EO.Pdf.PdfDocument();
string url = "http://localhost/WebClient/Dashboard";
HtmlToPdf.Options.MaxLoadWaitTime = 1000;
HtmlToPdf.Options.MaxLoadWaitTime = 30000;
HtmlToPdf.Options.TriggerMode = HtmlToPdfTriggerMode.Manual;
HtmlToPdf.Options.NoLink = true;
HtmlToPdf.Options.PreserveHighResImages = false;
HtmlToPdf.ConvertUrl(url, doc);
doc.Save(ms);
ms.Position = 0;
if (ctx != null)
ctx.Undo();
return new FileStreamResult(ms, "application/pdf")
{
FileDownloadName = "NSSDashboard.pdf"
};
}
In the dashboard view I load 6 partial views and in my Layout page I have placed this to trigger the conversion.
Code: JavaScript
jQuery(document).ajaxStop(function () {
if (typeof (eopdf) == "object") {
eopdf.convert();
}
});
Converting times out 9 times of 10.
But if I remove two out of 6 controls/partial views. No matter which ones then it is fine. None of these partial views include extra javascript files or anything like that. All those things are done from the Layout page.
I am using the latest package from the NuGet. Hit me if you need more info.