如何将 HTML 和 CSS 添加到 PDF 中 [英] How Can I add HTML And CSS Into PDF

查看:92
本文介绍了如何将 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:实际上我的运气更好.它渲染了一些图像(所有图像都是谷歌图表 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:

看看 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 解决方案,它可以实现完整的 酸2 ?

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天全站免登陆