Html 如何将 HTML5 / CSS3 文档转换为 PDF?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4027354/
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
How would I convert a HTML5 / CSS3 document to PDF?
提问by Jeffrey Fuller
We're currently generating reports for our web application using html5 / css3, and they look good on screen, but obviously when the user hits print who knows what is going to come out of the printer. So, what I would like to know is what is the best way to convert these reports to PDF for download / printing while maintaining the same visual quality of the on screen reports.
我们目前正在使用 html5 / css3 为我们的 web 应用程序生成报告,它们在屏幕上看起来不错,但很明显,当用户点击打印时,谁知道打印机会输出什么。所以,我想知道的是,将这些报告转换为 PDF 以供下载/打印,同时保持屏幕报告的相同视觉质量的最佳方法是什么。
Update 2010-10-26 16:01:We're using both .NET and Perl
更新 2010-10-26 16:01:我们同时使用 .NET 和 Perl
采纳答案by Mark Storer
The only think I can think of that mightwork is wkHTMLtoPDF. It's a QT app that sits on top of WebKit to generate its PDF.
唯一觉得我能想到的,威力工作wkHTMLtoPDF。这是一个 QT 应用程序,位于 WebKit 之上以生成其 PDF。
The good news is that it even evaluates JS so just about anything goes.
好消息是它甚至可以评估 JS,所以几乎任何事情都会发生。
The bad news (for you) is that it uses QT, which is an X11 windowing thingy. Given that you're using .NET I'm guessing you're a windows shop, which means extra installer headaches.
坏消息(对你来说)是它使用了 QT,这是一个 X11 窗口化的东西。鉴于您使用的是 .NET,我猜您是一家 windows 商店,这意味着额外的安装程序令人头疼。
回答by foolip
Try Prince XML, the results are pretty to look at.
试试Prince XML,结果很好看。
回答by charpdevel0p3r
ExpertPdf (www.html-to-pdf.net) supports html5 / css3.
ExpertPdf ( www.html-to-pdf.net) 支持 html5 / css3。
You can try the online demo here: http://www.html-to-pdf.net/free-online-pdf-converter.aspx
您可以在这里尝试在线演示:http: //www.html-to-pdf.net/free-online-pdf-converter.aspx
回答by dwjohnston
There is a node module html5-to-pdfthat works pretty well.
有一个节点模块html5-to-pdf运行良好。
Is free and open source.
是免费和开源的。
It runs on Electron. There are some bugs (for example anchor tags render the hyperlink as well) - but it might be an easy fix.
它在电子上运行。有一些错误(例如锚标记也会呈现超链接) - 但它可能是一个简单的修复。
回答by Lachezar
If you are using some of the new HTML5 elements like Canvas, then probably even the popular PDF converter wont help you.
如果您正在使用一些新的 HTML5 元素,例如 Canvas,那么即使是流行的 PDF 转换器也可能帮不到您。
I suggest you to put suitable print-friendly version of your CSS. This could be achieved by using media="print"
attribute in the <link rel="stylesheet"...
tag of a separate CSS file, which is containing the definitions for print version.
我建议您放置合适的 CSS 打印友好版本。这可以通过media="print"
在<link rel="stylesheet"...
单独的 CSS 文件的标签中使用属性来实现,该文件包含打印版本的定义。
回答by rsenna
Some options (all proprietary):
一些选项(所有专有):
- Aspose.Pdf for .NET: Expensive, very good though.
- Winnovative HTML to PDF Converter: I've already use their tool, gets the job done.
- ExpertPDF: Another good one.
- Aspose.Pdf for .NET:昂贵,但非常好。
- Winnovative HTML to PDF Converter:我已经使用了他们的工具,完成了工作。
- ExpertPDF:另一个不错的。
For open-source alternatives, please see here:
有关开源替代方案,请参见此处: