具有完全CSS支持的开源HTML到PDF渲染器

时间:2022-02-18 06:52:49

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.

我问过让iTextSharp在这之前从HTML和CSS表格中呈现PDF,但似乎这可能是不可能的...所以我想我将不得不尝试别的东西。

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

是否有一个开源的.NET / C#库可以将HTML和CSS作为输入并正确呈现它?

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

我必须重申......图书馆必须是免费的,最好是具有相当*许可的东西。我在这里基本上没有预算。

7 个解决方案

#1


15  

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).

我总是在命令行上使用它,而不是作为库,但HTMLDOC给了我很好的结果,它至少处理一些CSS(我不能轻易看到多少)。

Here's a sample command line

这是一个示例命令行

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

#2


37  

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

这个命令行工具就是生意! 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.

它使用webkit渲染引擎(在safari和KDE中使用),我在一些复杂的站点上测试它,它远远优于任何其他工具。

#3


2  

Do you see :

你有看到 :

They look as PrinceXML

他们看起来像PrinceXML

#4


0  

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

它不是开源的,但你至少可以获得Prince的免费个人使用许可,这真的很棒。

#5


0  

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

你可以尝试我的wkhtmltopdf包装器:https://github.com/pruiz/WkHtmlToXSharp;)

#6


-1  

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.

几年来,我们一直使用html2pdf生成带有自定义字体的高风格PDF文档。设置起来有点困难,但一旦设置好,它就会很好......而且它是免费的。

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

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

#7


-2  

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.

尝试使用webSupergoo中的ABCpdf。这是一个商业解决方案,不是开源的,但标准版可以免费获得,并将按照您的要求进行。

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.

ABCpdf完全支持HTML和CSS,实时表单和实时链接。它还在渲染时使用Microsoft XML Core Services(MSXML),因此结果应与您在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/

在线演示可用于测试HTML到PDF的渲染,而无需安装任何软件。请参阅:http://www.abcpdfeditor.com/

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

以下C#代码示例演示如何呈现单页HTML文档。

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

要渲染多个页面,您需要AddImageToChain函数,如下所示:http://www.websupergoo.com/helppdf7net/source/5-abcpdf6/doc/1-methods/addimagetochain.htm

#1


15  

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).

我总是在命令行上使用它,而不是作为库,但HTMLDOC给了我很好的结果,它至少处理一些CSS(我不能轻易看到多少)。

Here's a sample command line

这是一个示例命令行

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

#2


37  

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

这个命令行工具就是生意! 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.

它使用webkit渲染引擎(在safari和KDE中使用),我在一些复杂的站点上测试它,它远远优于任何其他工具。

#3


2  

Do you see :

你有看到 :

They look as PrinceXML

他们看起来像PrinceXML

#4


0  

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

它不是开源的,但你至少可以获得Prince的免费个人使用许可,这真的很棒。

#5


0  

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

你可以尝试我的wkhtmltopdf包装器:https://github.com/pruiz/WkHtmlToXSharp;)

#6


-1  

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.

几年来,我们一直使用html2pdf生成带有自定义字体的高风格PDF文档。设置起来有点困难,但一旦设置好,它就会很好......而且它是免费的。

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

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

#7


-2  

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.

尝试使用webSupergoo中的ABCpdf。这是一个商业解决方案,不是开源的,但标准版可以免费获得,并将按照您的要求进行。

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.

ABCpdf完全支持HTML和CSS,实时表单和实时链接。它还在渲染时使用Microsoft XML Core Services(MSXML),因此结果应与您在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/

在线演示可用于测试HTML到PDF的渲染,而无需安装任何软件。请参阅:http://www.abcpdfeditor.com/

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

以下C#代码示例演示如何呈现单页HTML文档。

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

要渲染多个页面,您需要AddImageToChain函数,如下所示:http://www.websupergoo.com/helppdf7net/source/5-abcpdf6/doc/1-methods/addimagetochain.htm