How to save Rotativa PDF on the server

I use Rotativa to create a PDF file in my "MVC" application. How to save a Rotativa PDF file? I need to save the document on the server after the process is complete.

Code below:

public ActionResult PRVRequestPdf(string refnum,string emid) { var prv = functions.getprvrequest(refnum, emid); return View(prv); } public ActionResult PDFPRVRequest() { var prv = Session["PRV"] as PRVRequestModel; byte[] pdfByteArray = Rotativa.WkhtmltopdfDriver.ConvertHtml("Rotativa", "Approver", "PRVRequestPdf"); return new Rotativa.ViewAsPdf("PRVRequestPdf", new { refnum = prv.rheader.request.Referenceno }); } 
+5
source share
2 answers

You can try try

 var actionResult = new ActionAsPdf("PRVRequestPdf", new { refnum = prv.rheader.request.Referenceno, emid = "Whatever this is" }); var byteArray = actionResult.BuildPdf(ControllerContext); var fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write); fileStream.Write(byteArray, 0, byteArray.Length); fileStream.Close(); 

If that doesn't do the trick, you can follow the answers here

Just make sure that if you do this so that PRVRequestPdf does not return as a PDF view, but looks like the normal view like yours above (just mentioning how this could be done is that I invoke a lot pleasure).

+12
source

Another useful answer:

I found a solution here

  var actionPDF = new Rotativa.ActionAsPdf("YOUR_ACTION_Method", new { id = ID, lang = strLang } //some route values) { //FileName = "TestView.pdf", PageSize = Size.A4, PageOrientation = Rotativa.Options.Orientation.Landscape, PageMargins = { Left = 1, Right = 1 } }; byte[] applicationPDFData = actionPDF.BuildPdf(ControllerContext); 

This is the original stream.

+2
source

Source: https://habr.com/ru/post/1205695/


All Articles