PHP direct printing using printer_write function

Discussion in 'PHP' started by karthik kithrak, Feb 24, 2018.

  1. #1
    Hello,
    I am working on a project which is generates invoice using php & html. i want to print that invoice directly to default printer using php. Seems printer_write function prints only source code & not the output view. So i created invoice into PDF using FPDF. Still i cant able to print PDF file using printer_write function. Any suggestions?

    My sample code:
    $pHandle = fopen("files/sample.pdf", "r");
    $handle = printer_open("HP LaserJet 1020");
    printer_set_option($handle, PRINTER_MODE, "RAW");
    printer_write($handle,$pHandle);
    printer_close($handle);
     
    karthik kithrak, Feb 24, 2018 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    Why using PHP for this. Use this in HTML: <body onload="window.print();">
     
    JEET, Mar 30, 2018 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Second option is this.
    at the very end of your HTML page, put this code:

    <script type="text/javascript">
    window.print();
    </script>

    This is recommended by some,
    argument being that the printing starts only after the page is completely loaded...

    However, the onload attribute inside <body> gets executed only when the page is completely loaded...
    So pretty much same thing.
    https://www.w3schools.com/tags/ev_onload.asp
     
    JEET, Mar 30, 2018 IP