asp.net mvc 使用NReco.PdfGenerator导出pdf
使用方法
- Download the package and add reference to the NReco.PdfGenerator.dll assembly OR install NReco.PdfGenerator nuget package
- 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);
- Create PDF from HTML file or URL (WebForms, MVC page):
htmlToPdf.GeneratePdfFromFile("http://www.nrecosite.com/", null, "export.pdf");
- That's all! See also online PdfGenerator API documentation.
- 若出现乱码 设置html编码格式 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />