使用php将网页打印到pdf文档 [英] Print a webpage to pdf document using php

查看:384
本文介绍了使用php将网页打印到pdf文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到有一些方法可以做到这一点.我的问题是,是否有人知道我可以简单地将php网页传递给pdf创建器,并且其输出与通过浏览器查看时完全相同的方式吗?考虑CSS,图像和php函数等.

I can see there are a few options for doing this. My question is does any one know of a way that I can simply pass a php web page into a pdf creator and it outputs exactly the same as if it was viewed via a browser? Taking into consideration CSS, images and php functions etc.

谢谢

推荐答案

认为 wkhtmltopdf 是您正在寻找的答案因为它使用 WebKit 来呈现网页,就像在浏览器中看起来一样,然后将其转换为PDF.这样可以节省编写大量PHP代码来组织PDF布局的麻烦.

Think wkhtmltopdf is the answer you are looking for as it uses WebKit to render the webpage just like it would look in a browser and then converts it to a PDF. This saves you writing a load of PHP code to organise the layout of your PDF.

其网站上的详细信息:

用于转换html的简单shell实用程序 使用webkit渲染到pdf 引擎和qt.

Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.

在网上搜索,我发现了 几个允许使用的命令行工具 您将HTML文档转换为 PDF文档,但是它们似乎都 用自己的,而不完整的 渲染引擎,导致效果不佳 质量.最近发布了QT 4.4 使用WebKit小部件(WebKit是 苹果Safari的引擎 KDE KHtml的分叉),然后制作一个 好的工具变得非常容易.

Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.

  • 使用webkit将网页转换为PDF文档
  • 添加页眉和页脚(仅静态版本)
  • TOC生成(仅静态版本)
  • 批处理模式转换
  • (Linux)不再需要XServer即可运行(但是X11 必须安装客户端库)
  • Convert web pages into PDF documents using webkit
  • Adding headers and footers (static version only)
  • TOC generation (static version only)
  • Batch mode conversions
  • (Linux) No longer requires an XServer to be running (however the X11 client libs must be installed)

有关与PHP集成 wkhtmltopdf 的代码和更多信息,请参见

For code and more information on wkhtmltopdf integration with PHP see https://github.com/aur1mas/Wkhtmltopdf

这篇关于使用php将网页打印到pdf文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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