在服务器上保存生成的pdf

时间:2016-05-16 07:02:06

标签: c# asp.net-mvc pdf rotativa

我正在使用ROTATIVA

从视图生成pdf
    public ActionResult StandartPDF()
    {
        var makeCvSession = Session["makeCV"];
        var something = new Rotativa.ViewAsPdf("StandartPDF", makeCvSession) { FileName = "cv.pdf" };
        return something;

    }

使用该代码用户可以下载它。但起初我想在服​​务器上。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

我在SaveOnServerPath class

中使用Rotativa属性解决了这个问题
public ActionResult StandartPDF()
    {

        var makeCvSession = Session["makeCV"];

        var root = Server.MapPath("~/PDF/");
        var pdfname = String.Format("{0}.pdf", Guid.NewGuid().ToString());
        var path = Path.Combine(root, pdfname);
        path = Path.GetFullPath(path);

        var something = new Rotativa.ViewAsPdf("StandartPDF", makeCvSession) { FileName = "cv.pdf", SaveOnServerPath = path };
        return something;

    }