I want to print (printer, not screen) the contents of a file using a PHP script.
How to do it?
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.
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.
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>";
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
Maybe this will help you. It offers a java library for sending print jobs via cmd on top of php scripts.
// 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;
Source: https://habr.com/ru/post/1347616/More articles:Mac OS X Disk Image Verification - dmgCan I use COM from Java through JNA? - javaWhy is creating a new thread expensive? - multithreadingsetSerializationId no such method error - javaCREATE DATABASE is permitted in the "master" database. MVC EF 4.1 Codefirst Getting Started - sqlThe connection string of the first MVC code. I changed that. How to reinitialize a database? - asp.net-mvcRemoving space blocks in Emacs - emacsJava properties files, using the key as another key value, possibly javaHow to wait for an image to be loaded from ajax () success data? - javascriptHow to "print" on paper in PHP? - javascriptAll Articles