将HTML + CSS转换为PDF [英] Convert HTML + CSS to PDF

查看:597
本文介绍了将HTML + CSS转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML(不是XHTML)文档,可以在Firefox 3和IE 7中很好地呈现.它使用相当基本的CSS对其进行样式设置,并在HTML中很好地呈现.

I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML.

我现在正在寻找一种将其转换为PDF的方法.我已经尝试过:

I'm now after a way of converting it to PDF. I have tried:

  • DOMPDF :它在表方面存在很大的问题.我考虑了我的大型嵌套表并对其有所帮助(在此之前,它只消耗了128M的内存然后就死了-这就是我对php.ini中的内存的限制),但是它使表完全混乱,并且似乎没有得到图片.表格只是基本的东西,带有一些边框样式,可以在各个点添加一些线;
  • HTML2PDF和HTML2PS :实际上,我对此很幸运.它呈现了一些图像(所有图像都是Google Chart URL),并且表格格式要好得多,但是似乎存在一些我尚未弄清楚的复杂性问题,并且一直死于未知的node_type()错误.不知道从这里去哪里;和
  • HTMLdoc :这在基本HTML上似乎可以正常使用,但几乎不支持CSS无论如何,因此您必须使用HTML进行所有操作(我没有意识到它在Htmldoc-land仍是2001年……),所以对我来说毫无用处.
  • DOMPDF: it had huge problems with tables. I factored out my large nested tables and it helped (before it was just consuming up to 128M of memory then dying--thats my limit on memory in php.ini) but it makes a complete mess of tables and doesn't seem to get images. The tables were just basic stuff with some border styles to add some lines at various points;
  • HTML2PDF and HTML2PS: I actually had better luck with this. It rendered some of the images (all the images are Google Chart URLs) and the table formatting was much better but it seemed to have some complexity problem I haven't figured out yet and kept dying with unknown node_type() errors. Not sure where to go from here; and
  • Htmldoc: this seems to work fine on basic HTML but has almost no support for CSS whatsoever so you have to do everything in HTML (I didn't realize it was still 2001 in Htmldoc-land...) so it's useless to me.

我尝试了一个名为Html2Pdf Pilot的Windows应用程序,该应用程序实际上做得不错,但是我需要的东西至少要在Linux上运行,并且最好在Web服务器上通过PHP按需运行.

I tried a Windows app called Html2Pdf Pilot that actually did a pretty decent job but I need something that at a minimum runs on Linux and ideally runs on-demand via PHP on the Webserver.

我缺少什么,或者如何解决此问题?

What am I missing, or how can I resolve this issue?

推荐答案

重要提示: 请注意,此答案写于2009年,可能不是2019年当今最具成本效益的解决方案.如今,在线替代方案比以前更好.

Important: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2019. Online alternatives are better today at this than they were back then.

以下是您可以使用的一些在线服务:

Here are some online services that you can use:

  • PDFShift
  • Restpack
  • PDF Layer
  • DocRaptor
  • HTMLPDFAPI
  • HTML to PDF Rocket

看看 PrinceXML .

虽然它不是免费的,但它绝对是最好的HTML/CSS到PDF转换器(但是,您的编程也可能不是免费的,因此,如果它节省了10个小时的工作时间,那么您就可以免费在家工作了(因为您还需要考虑到替代解决方案将需要您使用正确的软件来设置专用服务器)

It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But hey, your programming might not be free either, so if it saves you 10 hours of work, you're home free (since you also need to take into account that the alternative solutions will require you to setup a dedicated server with the right software)

哦,是的,我是否提到这是第一个(可能也是唯一)完整的HTML2PDF解决方案, ACID2 吗?

Oh yeah, did I mention that this is the first (and probably only) HTML2PDF solution that does full ACID2 ?

PrinceXML示例

这篇关于将HTML + CSS转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆