在 Python、.Net 或命令行中将 FOSS HTML 转为 PDF?

发布于 2024-07-13 22:21:54 字数 234 浏览 7 评论 0 原文

我尽可能多地谷歌,检查了几次 stackoverflow,但我找不到一个好的 html 到 pdf 转换器 可以处理 css。 是否有免费的开源解决方案(即使用于商业用途)? 有很多解决方案,价格范围也多种多样,但我一直在寻找开源且免费的解决方案。 我已经尝试过 Python 的 PISA,它运行得相当好,但对于商业用途来说不是免费的。 有什么适用于.Net 的吗? 我还没有成功使用 iTextSharp。

I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good html to pdf converter that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking for something open source and free. I have tried PISA for Python and it works fairly well, but is not free for commercial usage. Is there anything for .Net? I have not had success with iTextSharp.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

苯莒 2024-07-20 22:21:54

我在几个项目中使用了 wkhtmltopdf 。 http://code.google.com/p/wkhtmltopdf/。 它使用为 Safari 浏览器提供支持的 webkit 渲染引擎。 您将获得完全最新的渲染效果,就像使用 CSS 等的 Web 浏览器一样。

哦,它是开源的。

I've wkhtmltopdf used on a couple of projects. http://code.google.com/p/wkhtmltopdf/. It uses the webkit rendering engine, which powers the Safari browser. You'll get completely up to date rendering just like a web browser with CSS and all.

Oh, and it's open source.

一瞬间的火花 2024-07-20 22:21:54

我还没有找到一个好的 FOSS 解决方案,但我可以说 PrinceXML 工作得很好,提供了相当多的通过命令行提供一些功能,并且价格非常合理。 IIRC,免费版本会在您生成的每个 PDF 中附加一个封面页,这对您来说可能是也可能不是交易杀手,但您绝对应该检查一下。

I haven't found a good FOSS solution, but I can say that PrinceXML works very well, provides quite a bit of functionality through the command-line and is priced very reasonably. IIRC, the free version appends a cover page to each PDF you produce, which may or may not be a deal-killer for you, but you should definitely check it out.

栖竹 2024-07-20 22:21:54

您询问有关 C#/.NET 的事实让我猜测您使用的是 Windows 平台,因此这可能不适合您,但我使用 html2psps2pdf

#! /bin/sh

TEMPDIR="/tmp"
html2ps -u $1 > $TEMPDIR'temp.ps'
ps2pdf $TEMPDIR'temp.ps' $2

它确实处理 CSS(至少是我抛出的所有 CSS到目前为止),但如果我没记错的话,对于某些内嵌样式,还是有一些限制的。

注意:我认为这些都可以通过 Cygwin 在 Windows 上使用,如果这对您来说是可以接受的解决方案。

The fact that you're asking about C#/.NET makes me guess you're on a Windows platform, so this may not work for you, but I've had decent success using html2ps in conjunction with ps2pdf:

#! /bin/sh

TEMPDIR="/tmp"
html2ps -u $1 > $TEMPDIR'temp.ps'
ps2pdf $TEMPDIR'temp.ps' $2

That does handle CSS (at least all the CSS I've thrown at it so far) though there are some limitations if I remember right with regards to some in-line styles.

NOTE: I think these are both available on Windows via Cygwin, if that's an acceptable solution for you.

北凤男飞 2024-07-20 22:21:54

您还可以尝试不同的方法,例如使用虚拟打印机。

You can also try different approach like using virtual printers.

蔚蓝源自深海 2024-07-20 22:21:54

我使用此处找到的“PISA”xhtml2pdf 工具取得了惊人的成功:http://www.xhtml2pdf.com/

不要被“xhtml”部分吓到,它接受大范围的 html 输入,并根据 CSS 生成 PDF,包括 CSS 打印扩展。

I have had stunning success using the 'PISA' xhtml2pdf tool found here: http://www.xhtml2pdf.com/

Don't be scared off by the 'xhtml' part, it accepts a large range of html input, and produces PDFs according to CSS, including CSS print extensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文