NUGET 安装 Select.HtmlToPdf库
代码如下:
public class PdfUtils { /// <summary> /// html字符串转PDF /// </summary> /// <param name="html">html</param> /// <param name="pdfFileName">生成的pdf路径</param> public static void HtmlToPdfFile(string html, string pdfFileName) { HtmlToPdf htmlToPdf = new HtmlToPdf(); var docStr = htmlToPdf.ConvertHtmlString(html); PdfDocument doc = new PdfDocument(); doc.Append(docStr); doc.Save(pdfFileName); doc.Close(); } }