我正在使用Rotativa在我的“MVC”应用程序中生成PDF.如何保存Rotativa PDF?所有过程完成后,我需要将文档保存在服务器上.
代码如下:
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 }); }
解决方法
你可以尝试一下
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,byteArray.Length); fileStream.Close();
如果那样做不起作用,你可以按照答案here
只要确保你是这样做的,不要让PRVRequestPdf作为PDF视图返回,而不是像上面那样的普通视图(只提到我自己犯了很多乐趣).