views:

460

answers:

5

What I mean is, lets say I have a content:

"Stackoverflow is the best, bla bla bla..."

I want to print the content in a paper, not computer monitor, how to do that?

I saw a lot of CMS using php, have a print icon, and able to print it? (Well, I am not creating a CMS, just wondering how the printing works in php)

+5  A: 

Those CMS are probably just calling the JavaScript method window.print to pop up the print dialog:

<span onclick="window.print()" class="pseudo-link">print this document</span>

The rest is then handled by the browser and operating system.

Gumbo
+2  A: 

Do you mean printing from the Web server or from the client? If from the client window.print() in JavaScript will do the trick- http://www.javascriptkit.com/howto/newtech2.shtml.

I ask because I have seen Web based systems that actually do the printing from the server!

RichardOD
+1  A: 

Use javascript for this

window.print();

window.print(): Opens the Print Dialog to print the current document.

rahul
+2  A: 

Printing on a client browser cannot be done by php. Its done by javascript.

<form>
<input type="button" value="Print This Page" onClick="window.print()" />
</form>

Its best to describe a print css for the page.

Krishna Kant Sharma
+3  A: 

A better way to do it is like this:

<a href="#" onclick="window.print(); return false;">Print Me</a>

Adding the return false; to the onclick event will stop the browser following the link, and using the <a> tag with the href will cause the link cursor to appear on mouseover. Without it there would just be an arrow cursor which doesn't always make it obvious it's a link.

Meep3D