如何在服务器上呈现网页(无GUI)进行打印? [英] How can I render a web page on the server (no GUI) for printing?

查看:243
本文介绍了如何在服务器上呈现网页(无GUI)进行打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用PHP脚本实际打印页面到办公室打印机。

I'm trying to print pages pragmatically with a PHP script, to an office printer.

这是我到目前为止所做的:

Here's what I've got so far:

我在服务器上安装了一台打印机,我可以通过命令行的print命令用PHP向它发送作业。我也可以用我的PHP脚本编写纯文本文件,然后将它们添加到print cue中。因此,使用PHP打印PHP生成的纯文本文件就可以了。

I have a printer installed on the server, and I can send jobs to it with PHP via the command line's print command. I can also write plain text files with my PHP script, and then add them to the print cue. So printing PHP generated plain text files with PHP works just fine.

问题是,如何使用PHP创建实际包含布局和图形的可打印文件?换句话说,如果我创建了一个带有images和css的网页,然后在Firefox中显示该页面,然后点击打印,这就是我想从打印机上下来的东西。除非它需要在没有GUI的系统上工作,并且没有用户干预。

The question is, how can I create printable files, using PHP, that actually incorporate layout and graphics? In other words, if I created a web page with images and css, and then displayed the page in Firefox, and clicked print, that's what I want to come off the printer. Except it needs to work on a system without a GUI, and without user intervention.

到目前为止,我有这些可能的想法:

So far I have these possible ideas:


  • 使用PHP PDF库生成PDF文件并将其添加到打印提示中(非常复杂以获得正确的定位)

  • Use a PHP PDF library to generate a PDF file and add that to the print cue (very complicated to get the positioning right)

使用GD库生成图像文件(将图像和文本合并为一个页面大小的图像),并将最终图像发送到打印机。

Use the GD library to generate an image file (merging images and text into one page-sized image), and sending the final image to the printer.

上述两种情况都很复杂,实施和维护都很繁琐。我想知道是否有更简单的解决方案?使用html和CSS布局页面将是最简单的选择。是否有可以从原始html / css标记生成呈现页面的PDF的库或脚本?

Both of the above are complicated though, and would be tedious to implement and maintain. I'm wondering if there might be a simpler solution? Laying out the page using html and CSS would be the easiest option. Is there a library or script that can produce a PDF of a rendered page from raw html/css markup?

或者在命令中运行firefox(或其他浏览器)的方法仅行模式,但具有完整的渲染功能,可以发送到pdf文件或打印机?

Or a way to run firefox (or another browser) in command line only mode, but has full rendering capabilities that could be sent to a pdf file or the printer?

长问题短 - 我正在寻找一种发送方式将html / css页面渲染到打印机......

Long question short- I'm looking for a way to send a rendered html/css page to a printer...

任何想法?

推荐答案

我会避免使用PHP PDF库,因为它对DIV和嵌套等有很多限制。你必须专门为PDF环境编写你的页面。

I would avoid using the PHP PDF library as it has a lot of constraints regarding DIVs and nesting, etc. You would have to write your pages specifically for the PDF environment.

查看此页面:
http://code.google.com/ p / wkhtmltopdf /

这可以从服务器(或PHP)运行,它实际上将使用webkit引擎(浏览器)来构建页面像一个普通的浏览器,并返回它,这样你就可以做任何你想要它。你应该可以打印,保存,发送电子邮件等等。(它们将是PDF格式)

This can be run from the server (or PHP) and it will actually use the webkit engine (browser) to build the page just like a normal browser and return it so you can do whatever you want with it. You should be able to print this, save it, email it, etc. (They will be in PDF format)

这篇关于如何在服务器上呈现网页(无GUI)进行打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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