使用PHP将HTML + CSS转换为PDF? [英] Convert HTML + CSS to PDF with PHP?

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

问题描述

好吧,我现在用这个砖头撞墙。



我有一个HTML(不是XHTML)文档,在Firefox 3和IE 7.它使用相当基本的CSS来对其进行样式化并在HTML中渲染。



现在我将其转换为PDF。我尝试过:




  • DOMPDF :它有表的巨大问题。我考虑了我的大型嵌套表,它帮助(之前它只消耗了128M的内存,然后死了 - 这是我对php.ini内存的限制),但它使一个完整的表混乱,似乎不会得到图片。表格只是一些边框样式的基本东西,可在不同点添加一些线条;

  • HTML2PDF和HTML2PS :我其实有更好的运气。它呈现了一些图像(所有的图像是谷歌图表URL)和表格式更好,但它似乎有一些复杂性的问题,我还没有想到,并继续与未知的node_type()错误死亡。不知道从哪里去;和

  • Htmldoc :这似乎工作基本的HTML,但几乎没有支持CSS什么,所以你必须做的一切HTML(我没有意识到,它仍然是2001年在Htmldoc-land ...),因此它对我没用。



我尝试过一个名为Html2Pdf Pilot的Windows应用程序,它实际上做了一个相当不错的工作,但我需要的东西,至少运行在Linux上,理想的是按需运行PHP在网络服务器上。



我真的不敢相信我被困住了。

看看 nofollow noreferrer> PrinceXML



这绝对是最好的HTML / CSS到PDF转换器,虽然它不是免费的免费,所以如果它节省你10个小时的工作,你回家免费(因为你还需要考虑到,替代解决方案将需要您设置一个专用的服务器与正确的软件)



哦,是的,我提到这是第一个(也许只有)HTML2PDF解决方案,完全 ACID2



PrinceXML示例



脚注:请注意,此答案是在2009年编写的, - 有效的解决方案今天在2017年。浏览器和其他开源渲染器已经成为了很多更好的在这比他们当时。


Ok, I'm now banging my head against a brick wall with this one.

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.

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

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

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.

I really can't believe I'm this stuck. Am I missing something?

解决方案

Have a look at PrinceXML.

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)

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

PrinceXML Samples

Footnote: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2017. Browsers and other open source renderers have become a lot better at this than they were back then.

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

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