Hi
I am trying to use the RenderAsPdf on MVC action result to print a PDF and save the file in the afterConvertHandler to the document. The file is generated but without the view content.
Code: C#
[HttpPost]
[RenderAsPDF(AutoConvert =false,SendToClient =false,ResultAsDownload =false)]
public ActionResult PrintView(string id)
{
--Code for license and other page size options
MVCToPDF.RenderAsPDF(afterPDFConvertHandler);
return ViewWithContent(paramters)
}
private void afterPDFConvertHandler(object sender, PdfDocumentEventArgs pdfDocEventHandler)
{
var result = MVCToPDF.Result;
if (result != null)
{
var fileName = Guid.NewGuid().ToString() + ".pdf";
result.PdfDocument.Save(Server.MapPath("~/Temp/" + fileName));
}
}
The afterPDFCovertHandler does get called but when it saves the file to the disk. There is no content in the file except the header and footer that I set in the options.
For some reason, the view is not getting rendered in the PDF. To top this, the browser is redirecting the Action method and showing up the empty pdf page on the browser window.
I am not sure if I am passing a wrong paramters or if my expectations are wrong. I do not want the pdf to be downloaded and instead saved to the disk which will be then emailed.
Any help on this is appreciated.