Convert HTML to PDF in ASP.NET MVC

前端 未结 8 673
陌清茗
陌清茗 2021-02-06 07:56

Im working in a project which requires current html page to convert in pdf and that pdf will automatically save on button click on server and its reference will be save in da

8条回答
  •  有刺的猬
    2021-02-06 08:13

    In short:

    HTML Renderer for PDF using PdfSharp

        public static Byte[] PdfSharpConvert(String html)
        {
            Byte[] res = null;
            using (MemoryStream ms = new MemoryStream())
            {
                var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);
                pdf.Save(ms);
                res = ms.ToArray();
            }
            return res;
        }
    

    More Detailed Answer

提交回复
热议问题