Hi everyone,
I'm having some issues with the following project:
- EO.PDF .NET 15.2.53.0
- ASP.NET 4.5.2 with hybrid Webforms + MVC 4
Below is my controller method.
Code: C#
using EO.Pdf;
using EO.Pdf.Mvc;
[RenderAsPDF]
public ActionResult PrintCalendar(string yearString, string monthString)
{
string fileName = string.Format("calendar");
MVCToPDF.ResultFileName = fileName;
HtmlToPdf.Options.PageSize = new SizeF(PdfPageSizes.A4.Height, PdfPageSizes.A4.Width);
const float marginLeft = 0.2f;
const float marginTop = 0.2f;
float pageHeight = PdfPageSizes.A4.Height - (marginTop * 2);
float pageWidth = PdfPageSizes.A4.Width - (marginLeft * 2);
HtmlToPdf.Options.OutputArea = new RectangleF(marginLeft, marginTop, pageHeight, pageWidth);
HtmlToPdf.Options.ZoomLevel = 0.8f;
HtmlToPdf.DebugConsole = Console.Out;
HtmlToPdf.Options.MinLoadWaitTime = 5000;
MVCToPDF.ResultAsDownload = true;
MVCToPDF.RenderAsPDF();
return View();
}
Within this View, I put some Javascript that calls another Controller Method to get some data. That's why I set at least 5 seconds load time. Calling this View without the RenderAsHtml command, works perfect.
When I call this (httpget) method, a download/save file as... dialog appears, but then nothing happens. I've waited for about 10 minutes. Also nothing is visible in the Debug-output console. The breakpoint on the controller method returning the data isn't hit.
Because I've registered the AuthorizeAttribute filter, I think the request might be unauthenticated?
Code: C#
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new AuthorizeAttribute());
}
To solve this, I thought it might be good to add the Authentication cookie to the HtmlToPdf.Options. When I just add all the cookies, it still doesn't respond. So I just add the FormsAuthentication cookie:
Code: C#
for (int i = 0; i < Request.Cookies.Count; i++)
{
HttpCookie httpCookie = Request.Cookies[i];
if (string.Equals(httpCookie.Name, "User", StringComparison.OrdinalIgnoreCase))
{
HtmlToPdf.Options.Cookies.Add(new Cookie() { Name = httpCookie.Name, Domain = httpCookie.Domain, Path = httpCookie.Path, Secure = httpCookie.Secure, Value = httpCookie.Value, Expires = httpCookie.Expires });
}
}
Then it works! My controller method, called by javascript, hits the breakpoint. But the Session ID is different. So it looks like it's run on a different thread or something creating a new Session ID. That's a problem, I'm missing some required data.
When I add the Session-cookie, the same way as I do with the authentication cookie, it hangs again. No breakpoint is hit.
So my first question is, am I using EO.PDF correct? Given the Hybrid webforms/MVC and EO version. Offcourse I've setup licence key and:
Code: C#
EO.Pdf.Mvc.MVCToPDF.RegisterFilter(typeof(GlobalFilters));
Am I doing the authentication-trick correct? I've seen a property MVCToPDF.AutoFormsAuthentication = true|false; but that doesn't seem to make any difference. Also I can't find the MVC4 namespace for using the RenderAsPDF-attribute?
Many thanks in advance.