Convert HTML to PDF in .NET

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

    As a representative of HiQPdf Software I believe the best solution is HiQPdf HTML to PDF converter for .NET. It contains the most advanced HTML5, CSS3, SVG and JavaScript rendering engine on market. There is also a free version of the HTML to PDF library which you can use to produce for free up to 3 PDF pages. The minimal C# code to produce a PDF as a byte[] from a HTML page is:

    HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
    
    // set PDF page size, orientation and margins
    htmlToPdfConverter.Document.PageSize = PdfPageSize.A4;
    htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Portrait;
    htmlToPdfConverter.Document.Margins = new PdfMargins(0);
    
    // convert HTML to PDF 
    byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
    

    You can find more detailed examples both for ASP.NET and MVC in HiQPdf HTML to PDF Converter examples repository.

提交回复
热议问题