use*_*485 9 rotativa asp.net-mvc-5
我正在使用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 });
}
Run Code Online (Sandbox Code Playgroud)
小智 17
你可以尝试一下
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();
Run Code Online (Sandbox Code Playgroud)
如果那样做不起作用,你可以按照这里的答案
只要确保你这样做就不要以PRVRequestPdfPDF视图的形式返回,而不是像上面那样的普通视图(只提到我自己犯了很多乐趣).
另一个有用的答案
我在这里找到了解决方案
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);
Run Code Online (Sandbox Code Playgroud)
这是原始主题
| 归档时间: |
|
| 查看次数: |
15068 次 |
| 最近记录: |