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

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

How to do it?

+4
source share
5 answers

Update

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

Cm:

However, as the first link shows, this is usually done using Javascript. You can output Javascript in the same way as the methods shown on the first link to make the browser display the print dialog. A.

Original

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

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

You can also include files in the interpretation of PHP.

+5
source

A quick and dirty way to print to a client computer is something like this:

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

This, of course, is not what your question is intended, but on any Linux server with a printer connected, you can use the following:

 exec("lp file.pdf"); // send file to printer spooler 
+1
source

Maybe this will help you. It offers a java library for sending print jobs via cmd on top of php scripts.

0
source
 // to open a local file use this $file_handler = fopen("data.txt", "r"); // read the contents $contents = fread($file_handler, filesize($file)); // close the file fclose($file_handler); // print the contents on your page echo $contents; 
-1
source

Source: https://habr.com/ru/post/1347616/


All Articles