Convert HTML to PDF in .NET

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

    To convert HTML to PDF in C# use ABCpdf.

    ABCpdf can make use of the Gecko or Trident rendering engines, so your HTML table will look the same as it appears in FireFox and Internet Explorer.

    There's an on-line demo of ABCpdf at www.abcpdfeditor.com. You could use this to check out how your tables will render first, without needing to download and install software.

    For rendering entire web pages you'll need the AddImageUrl or AddImageHtml functions. But if all you want to do is simply add HTML styled text then you could try the AddHtml function, as below:

    Doc theDoc = new Doc();
    theDoc.FontSize = 72;
    theDoc.AddHtml("Some HTML styled text");
    theDoc.Save(Server.MapPath("docaddhtml.pdf"));
    theDoc.Clear();
    

    ABCpdf is a commercial software title, however the standard edition can often be obtained for free under special offer.

提交回复
热议问题