如何在服务器上保存 Rotativa PDF [英] How to save Rotativa PDF on server

查看:23
本文介绍了如何在服务器上保存 Rotativa PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Rotativa 在我的MVC"应用程序中生成 PDF.如何保存 Rotativa 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.

代码如下:

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, 0, byteArray.Length);
fileStream.Close();

如果那还不行,你可以按照答案这里

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

只要确保你这样做不会让 PRVRequestPdf 作为 PDF 视图返回,而是像上面那样的普通视图(只提到我自己设法犯规,导致很多好玩).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆