How to “print” to a paper in PHP?

后端 未结 5 1668
难免孤独
难免孤独 2021-01-14 03:17

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

相关标签:
5条回答
  • 2021-01-14 03:40

    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.

    0 讨论(0)
  • 2021-01-14 03:40

    Use javascript for this

    window.print();
    

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

    0 讨论(0)
  • 2021-01-14 03:47

    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.

    0 讨论(0)
  • 2021-01-14 03:51

    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!

    0 讨论(0)
  • 2021-01-14 03:53

    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.

    0 讨论(0)
提交回复
热议问题