Open Source HTML to PDF Renderer with Full CSS Support [closed]

和自甴很熟 提交于 2019-11-27 00:05:40

问题


I asked about getting iTextSharp to render a PDF from HTML and a CSS sheet before here but it seems like that may not be possible... So I guess I will have to try something else.

Is there an open source .NET/C# library out there that can take HTML and CSS as input and render it correctly?

I must reiterate... the library MUST be free and preferably something with a fairly liberal license. I'm working with basically no budget here.


回答1:


I've always used it on the command line and not as a library, but HTMLDOC gives me excellent results, and it handles at least some CSS (I couldn't easily see how much).

Here's a sample command line

htmldoc --webpage -t pdf --size letter --fontsize 10pt index.html > index.pdf



回答2:


This command line tool is the business! https://wkhtmltopdf.org/

It uses webkit rendering engine(used in safari and KDE), I tested it on some complex sites and it was by far better than any other tool.




回答3:


Do you see :

  • http://www.xhtml2pdf.com
  • http://code.google.com/p/wkhtmltopdf/

They look as PrinceXML




回答4:


You could try my wkhtmltopdf wrapper: https://github.com/pruiz/WkHtmlToXSharp ;)




回答5:


It's not open source, but you can at least get a free personal use license to Prince, which really does a lovely job.




回答6:


Try ABCpdf from webSupergoo. It's a commercial solution, not open source, but the standard edition can be obtained free of charge and will do what you are asking.

ABCpdf fully supports HTML and CSS, live forms and live links. It also uses Microsoft XML Core Services (MSXML) while rendering, so the results should match exactly what you see in Internet Explorer.

The on-line demo can be used to test HTML to PDF rendering without needing to install any software. See: http://www.abcpdfeditor.com/

The following C# code example shows how to render a single page HTML document.

Doc theDoc = new Doc();
theDoc.AddImageUrl("http://www.example.com/");
theDoc.Save("htmlimport.pdf");
theDoc.Clear();

To render multiple pages you'll need the AddImageToChain function, documented here: http://www.websupergoo.com/helppdf7net/source/5-abcpdf6/doc/1-methods/addimagetochain.htm




回答7:


We have been using html2pdf for generating highly styled PDF documents with custom fonts, for a few years now. It's a little hard to get set up, but once it is, it works great... and it's free.

http://www.tufat.com/s_html2ps_html2pdf.htm



来源:https://stackoverflow.com/questions/430590/open-source-html-to-pdf-renderer-with-full-css-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!