开发者

Printing contents with PHP

I can't really find a topic on how to print a file with the printer. First off, I dont't mean print like echo, but a real printer.

I want to have the user click on a button, and th开发者_如何学编程an it starts printing the page.

The same as javascript:window.print() does, but than with PHP. Is there such option?

Thanks!


Do you mean printing on server-side or client side?

For client-side you can include a javascript snippet which calls the JS function you mentioned:

<?php
print '<input type="button" value="Print this document" onclick="window.print();" />\n';
?>

For server-side: it is definitely more complicated. You could either find a PHP interface, e.g. to CUPS (the standard UNIX printing system) or call a system program that prints the document. Svish posted a link to a CUPS interface as far as I see an interface to printing in MS Windows (useful only if the server is running under Windows, of course).

Edit: If you expect to find a solution which prints the page PHP outputs rendered by the client browser and but not printed on the client, but on the server -- this should be impossible. I guess you could implement sending the output of PHP the a system program that renders the page itself but it will never look 100% like on the client. Maybe it's acceptable to call a printing program on the server, pass all necessary information to it and it renders some document of its own, e.g. an RTF text file?


PHP works server-side and therefore cannot print anything on the client-side. It can't do anything on the client-side actually, other than via generated HTML, CSS, JavaScript, etc. PHP can talk to a printer though, but it would be a server-side printer as far as I know.

SO, if you want the user to click a button to print a page, on their printer, it would have to be something client-side. For example JavaScript.


As PHP is a server-side scripting language, this wouldn't be possible.


You cannot have the user print a document from his printer using PHP.

If the design of the printed document is undesirable, you can either add a print stylesheet.

Or have a printer friendly page. For example; passing a get variable called printer will have your php script echo another design of your page.

If you are talking about a server-side printer, you can.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜