HTML转pdf文件

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();
        }
    }

 

posted @ 2021-03-31 19:57  _York  阅读(16)  评论(0编辑  收藏  举报