Convert HTML to PDF in .NET

后端 未结 30 2457
不知归路
不知归路 2020-11-22 00:28

I want to generate a PDF by passing HTML contents to a function. I have made use of iTextSharp for this but it does not perform well when it encounters tables and the layout

30条回答
  •  佛祖请我去吃肉
    2020-11-22 00:41

    This is a free library and works very easily : OpenHtmlToPdf

    string timeStampForPdfName = DateTime.Now.ToString("yyMMddHHmmssff");
    
    string serverPath = System.Web.Hosting.HostingEnvironment.MapPath("~/FolderName");
    string pdfSavePath = Path.Combine(@serverPath, "FileName" + timeStampForPdfName + ".FileExtension");
    
    
    //OpenHtmlToPdf Library used for Performing PDF Conversion
    var pdf = Pdf.From(HTML_String).Content();
    
    //FOr writing to file from a ByteArray
     File.WriteAllBytes(pdfSavePath, pdf.ToArray()); // Requires System.Linq
    

提交回复
热议问题