使用方法 Download the package and add reference to the NReco.PdfGenerator.dll assembly OR install NReco.PdfGenerator nuget packageConvert 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" /> 转载于:https://www.cnblogs.com/coodream/p/5235235.html