Welcome Guest Search | Active Topics | Sign In | Register

Using RenderAsPDF to Save file to Disk and not download file to client Options
Vikram
Posted: Wednesday, December 7, 2016 11:40:17 PM
Rank: Member
Groups: Member

Joined: 3/6/2016
Posts: 19
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.
eo_support
Posted: Thursday, December 8, 2016 7:26:38 AM
Rank: Administration
Groups: Administration

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

RenderAsPDF should generate exactly the same output as on the screen. You can try to comment out RenderAsPDF and see if you get the same result on the screen. If you do get the same result on the screen, then the problem is somewhere else in your code and you will need to fix that first. If the problem does not occur when you comment RenderAsPDF out, then you can isolate the problem into a test project and send the test project to us:

https://www.essentialobjects.com/forum/test_project.aspx

Once we have that we will be happy to look further.

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.