Convert HTML to PDF in .NET

后端 未结 30 1805
不知归路
不知归路 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:43

    You need to use a commercial library if you need perfect html rendering in pdf.

    ExpertPdf Html To Pdf Converter is very easy to use and it supports the latest html5/css3. You can either convert an entire url to pdf:

    using ExpertPdf.HtmlToPdf; 
    byte[] pdfBytes = new PdfConverter().GetPdfBytesFromUrl(url);
    

    or a html string:

    using ExpertPdf.HtmlToPdf; 
    byte[] pdfBytes = new PdfConverter().GetPdfBytesFromHtmlString(html, baseUrl);
    

    You also have the alternative to directly save the generated pdf document to a Stream of file on the disk.

提交回复
热议问题