Send document (or string) directly to network printer

Discussion in 'PHP' started by stephan2307, Jun 1, 2010.

  1. #1
    Hi,

    Does anyone have any experience how to code it so I can send a document (or a string) directly to a network printer from a Linux machine using php?

    Thanks,

    Stephan
     
    stephan2307, Jun 1, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    OK I have managed to do it.

    Simply set up the printer on the server (installing drivers)
    and then use
    system('lpr document.doc');
    PHP:
    works like a dream
     
    stephan2307, Jun 1, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3

    Using system calls is generally poor practice; it is a blocking call for one thing and at the very least you shold be escaping the data you are passing into it
    (if it is selectable from the users, that is).

    There are plenty of other (better) ways to do this; using CUPS is pretty standard, through a SOAP request or such, or directly to a stream.

    You might also want to check the docs for the built in printer functions;
    NOTE: These are for windows machines and not unix as you have specified, but if you check the comments listed, there's at least 1 example of achieving it on a unix box.

    http://php.net/manual/en/ref.printer.php

    If you are happy using the system call, then so be it - just thought I'd add a comment about using it.
     
    lukeg32, Jun 1, 2010 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    Thanks for your info.

    I will have a look at your suggestions.
     
    stephan2307, Jun 1, 2010 IP