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
Author by
Jugal Patel
Updated on July 09, 2022Comments
-
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 about 13 yearsI 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 over 9 yearsThis doesn't answer what OP wants, to print the file on the physical printer.