如何保存在服务器上Rotativa PDF [英] How to save Rotativa PDF on server
问题描述
。我如何保存Rotativa PDF?我需要将文档保存在服务器上完成所有工序。
code如下:
公众的ActionResult PRVRequestPdf(字符串引用句柄,字符串EMID)
{
VAR PRV = functions.getprvrequest(引用句柄,EMID);
返回查看(PRV);}
公众的ActionResult PDFPRVRequest()
{
VAR PRV =会话[PRV]作为PRVRequestModel;
字节[] = pdfByteArray Rotativa.WkhtmltopdfDriver.ConvertHtml(Rotativa,审批,PRVRequestPdf);
返回新Rotativa.ViewAsPdf(PRVRequestPdf,新的{引用句柄= prv.rheader.request.Referenceno});}
能给这个一展身手
VAR的ActionResult =新ActionAsPdf(PRVRequestPdf,新的{引用句柄= prv.rheader.request.Referenceno,EMID =无论这是});
VAR的字节数组= actionResult.BuildPdf(ControllerContext);
VAR FILESTREAM =新的FileStream(FULLPATH,FileMode.Create,FileAccess.Write);
fileStream.Write(字节数组,0,byteArray.Length);
fileStream.Close();
如果不这样的伎俩则可以按照答案<一个href=\"http://stackoverflow.com/questions/11854642/how-do-i-intercept-the-output-stream-of-the-current-actionresult-in-net-mvc3\">here
只要确定,如果你做这种方式不具有PRVRequestPdf回报为PDF浏览,而一个正常查看像你有以上(只提为设法落在犯规自己造成很多的乐趣)
I am using Rotativa to generate PDF in my "MVC" application. How can I save Rotativa PDF? I need to save the document on a server after all the process is completed.
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 });
}
Could give this a go
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 then can follow the answers here
Just make sure if you do it this way not to have PRVRequestPdf return as a PDF View, rather a normal View like you have above (only mention as managed to fall foul of that myself causing lots of fun)
这篇关于如何保存在服务器上Rotativa PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!