asp.net mvc 使用NReco.PdfGenerator导出pdf

使用方法

  1. Download the package and add reference to the NReco.PdfGenerator.dll assembly OR install NReco.PdfGenerator nuget package
  2. Convert HTML to PDF with one line of C# code:
    var htmlContent = String.Format("<body>Hello world: {0}</body>", 
    		DateTime.Now);
    var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
    var pdfBytes = htmlToPdf.GeneratePdf(htmlContent);
  3. Create PDF from HTML file or URL (WebForms, MVC page):
    htmlToPdf.GeneratePdfFromFile("http://www.nrecosite.com/", null, "export.pdf");
  4. That's all! See also online PdfGenerator API documentation.
  5. 若出现乱码 设置html编码格式 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
posted @ 2016-03-02 15:48  coodream  阅读(1399)  评论(0编辑  收藏  举报