How to send the content of an external file to printer?

34,014

Solution 1

Update

php cannot easily access hardware. This is generally not considered "possible."

See:

However, as the first link shows, this is usually done with Javascript. You can output Javascript in a way similar to the methods shown on the first link to force the browser to show the print dialog box.

Original

You can use file_get_contents to print files into a variable or to the output stream.

$filecontents = file_get_contents("myfilename.txt");
print $filecontents;

You can also include files into your PHP interpretation.

Solution 2

A quick and dirty way to print on the client's computer is something like:

print file_get_contents("file.ext");
print "<script>window.print()</script>";

Solution 3

This is certainly not what your question intended, but on any Linux server with a connected printer you could use following:

exec("lp file.pdf");   // send file to printer spooler
Share:
34,014
Jugal Patel
Author by

Jugal Patel

Updated on July 09, 2022

Comments

  • Jugal Patel
    Jugal Patel almost 2 years

    I want to print (printer, not screen) the content of a file via a PHP script.

    How do I do this?

  • Jugal Patel
    Jugal Patel about 13 years
    I want to give a print command to a printer...! Read the content and print a file remotely via PHP script...! CAn u pls help me with that..???
  • glerYbo
    glerYbo over 9 years
    This doesn't answer what OP wants, to print the file on the physical printer.