Asp.Net MVC how to get view to generate PDF

前端 未结 8 1573
醉酒成梦
醉酒成梦 2020-11-28 19:09

I would like to call an action on a controller. Have the controller get the data from the model. The view then runs and generates a PDF. The only example I have found i

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 19:59

    our final answer to this problem was to use Rotativa.

    It wraps up the WKhtmltopdf.exe like some of the other solutions, but it's by far the easiest to use that I have found

    I went and up voted all the other answers that also solve the problem well, but this is what we used to solve the problem posed in the question above. It is different from the other answers.

    Here is a Rotativa Tutorial.

    after you install it, this is all your need

    public ActionResult PrintInvoice(int invoiceId)
    {
      return new ActionAsPdf(
                     "Invoice", 
                     new { invoiceId= invoiceId }) 
                     { FileName = "Invoice.pdf" };
    }
    

    Very Very simple.

提交回复
热议问题