Welcome Guest Search | Active Topics | Sign In | Register

MVC4 and MVC5 different behaviour in OnResultExecuted Options
Dimitris
Posted: Tuesday, November 28, 2017 9:14:05 AM
Rank: Newbie
Groups: Member

Joined: 11/28/2017
Posts: 1
Hi there,
I once built an application based on the EO.Pdf.MVC4 lib. (Under VS2013). That used to be version 5.0.82.2.
What it did essentially, is that before returning the PDF to the user, it would make some changes.
I used to use the override of OnResultExecuted. So, the code would be:

[RenderAsPDF(AutoConvert = false)]
public ActionResult Render(string parametersJson, string output, string id)
{
...
MVCToPDF.SendToClient = false;
MVCToPDF.RenderAsPDF();
...
return View("foo", model);
}

and later on:

// takes place when MVCToPDF.RenderAsPDF() is executed (with send to client = false)
protected override void OnResultExecuted(ResultExecutedContext filterContext)
{
HtmlToPdfResult result = MVCToPDF.Result;
if (result != null)
{
var tempPdfFullPath = Path.Combine(Path.GetTempPath(), String.Format("{0}.pdf", _tempPdfGuid));
result.PdfDocument.Save(tempPdfFullPath);
filterContext.Result = File(tempPdfFullPath, "application/pdf");
}

base.OnResultExecuted(filterContext);
}

at that period, the HtmlToPdfResult result = MVCToPDF.Result would result in a NON-NULL object. So result variable was not null.

Recently, I decided to take this application seriously and get over with it. So I got all the latest stuff and also downloaded the code samples, by having the latest version of 17.3.13.

So, in the code example in solution EO.Total.Samples and project PdfMvc_CS, there is a similar code:

[HttpPost]
[EO.Pdf.Mvc.RenderAsPDF(AutoConvert=false)]
public ActionResult Input(AddressModel m)
{
if (m.ExportToPDF)
{
MVCToPDF.ResultFileName = "AddressLabel";
if (m.SaveAsFile)
MVCToPDF.SendToClient = false;
MVCToPDF.RenderAsPDF();
}

return View("AddressLabel", m);
}

protected override void OnResultExecuted(ResultExecutedContext filterContext)
{
base.OnResultExecuted(filterContext);

EO.Pdf.HtmlToPdfResult result = MVCToPDF.Result;
if (result != null)
{
//Uncomment the following line to save the result
//to a file
//result.PdfDocument.Save(pdfFileName);
}
}

The thing is now that "result" is NULL because now MVCToPDF.Result is null too.
This is not good.
I tried using the new callbacks, by adding MVCToPDF.RenderAsPDF(Post_Handler) but this is for saving to disk the PDF file.
What about modifying and using filterContext.Result = File(tempPdfFullPath, "application/pdf") ?
filterContext does not exist in the callback, so I can return content type application/pdf only at the OnResultExecuted (which is called BEFORE the callback Post_Handler, so it's no use to do that anymore as the PDF file has not yet been generated.

Any help would be appreciated!

Regards
Dimitris


eo_support
Posted: Friday, December 1, 2017 9:49:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

Thanks for bring this to our attention. This was due to a change on our end that delayed the HTML to PDF conversion as late as possible. As a result, the conversion result is no longer available in OnResultExecuted. However the corresponding sample code has not been updated to reflect this. We will update them in our next build.

If you wish to send the PDF file directly down to the client browser, you can use MVCToPDF.SendToClient, MVCToPDF.ResultFileName and MVCToPDF.ResultAsDownload property. For example, if you just want the PDF file to be opened directly in the browser, you can send SendToClient to true and ResultAsDownload as false.

Please feel free to let us know if you still have any questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.