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

查看:34
本文介绍了使用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.

来自他们网站的详细信息:

Details from their site:

用于转换 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 是Apples 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必须安装客户端库)

有关 wkhtmltopdf 与 PHP 集成的代码和更多信息,请参阅https://github.com/aur1mas/Wkhtmltopdf

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

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

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