对于 html 到 pdf 的转换,windows 上是否有 wkhtmltopdf 的可行替代方案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2600353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:14:54  来源:igfitidea点击:

Are there any viable alternatives to wkhtmltopdf on windows, for html to pdf conversion?

htmlwindowsopen-sourcecross-platformpdf-generation

提问by DevelopingChris

I've found wkhtmltopdf, which looks good on the surface and works fine in very small cases, but it doesn't provide any real css control over the rendering.

我找到了 wkhtmltopdf,它表面上看起来不错,在非常小的情况下也能正常工作,但它没有提供对渲染的任何真正的 css 控制。

By that I mean it doesn't use the print media type and page breaks are not respected, as well, on windows you can't control the names of some header/footer variables, or generate a TOC off of teh h1 tags.

我的意思是它不使用印刷媒体类型并且不考虑分页符,同样,在 Windows 上,您无法控制某些页眉/页脚变量的名称,或从 h1 标签生成 TOC。

Are there any real open source alternatives, I've tried xhtml2pdf which is a python library actually called pisa, but it requires reportlab which doesn't play nice windows.

是否有任何真正的开源替代品,我试过 xhtml2pdf,它是一个实际称为 pisa 的 python 库,但它需要 reportlab,它不能播放漂亮的窗口。

I'm actually programming in .net but if its good and open source, the language isn't a huge issue.

我实际上是在 .net 中编程,但如果它是好的和开源的,那么语言不是一个大问题。

采纳答案by DevelopingChris

It turns out there was no open source alternative that was simpler, but on windows wkhtmltopdf is just not the best thing, so we paid for a better solution.

事实证明,没有比这更简单的开源替代方案,但在 windows 上 wkhtmltopdf 并不是最好的选择,因此我们为更好的解决方案付费。

Winnovative's PDF library is what we used

我们使用的是 Winnovative 的 PDF 库

回答by yvess

This is an old stackoverflow question, but because google took me here, it could be helpful for somebody else. Weasyprint should support what the author was looking for.
It supports print css features like page break.

这是一个古老的 stackoverflow 问题,但因为谷歌把我带到这里,它可能对其他人有帮助。Weasyprint 应该支持作者正在寻找的内容。
它支持打印 css 功能,如分页符。

Try weasyprint

试试weasyprint

回答by Diodeus - James MacFarlane

While it is not open-source, I use ABCPDF. I have a template page in .NET that I use for a wrapper to set up a custom stylesheet for generating PDFs only.

虽然它不是开源的,但我使用ABCPDF。我在 .NET 中有一个模板页面,用于包装器来设置自定义样式表,仅用于生成 PDF。