2

Hey I am trying to print a text using php. This print should occur automatically. Now I am testing in normal HP deskjet printer but in future it prints through thermal printer. Now my code is

<?php
$printer = "\\\\LOCALHOST\\HP Deskjet 1510 series";
$fp = fopen($printer, "w");
$data = "hello";
fwrite($fp,$data);

This code runs fine with no error but no printing occurs.

printing status is like below enter image description here

please help..

1
  • This would require PHP access to the user's local system. Commented May 3, 2015 at 5:38

1 Answer 1

1

You can try the following code.

<?php
$printer = "\\\\LOCALHOST\\HP Deskjet 1510 series");
if($ph = printer_open($printer))
{   
   $data= "Hello";
   printer_set_option($ph, PRINTER_MODE, "RAW");
   printer_write($ph, $data);
  printer_close($ph);
}
 else "Couldn't connect...";
?>
Sign up to request clarification or add additional context in comments.

5 Comments

i get an error Fatal error: Call to undefined function printer_open()
do you have a php_printer.dll enabled? Use this link for downloading the file dlldll.com/php_printer.dll_download.html and in your php.ini file -> add the following : printer.default_printer=PHP_INI_ALL extension=php_printer.dll
The libray php_printer.dll must be loaded in your server(wamp or any other) in order for the above code to work. try restarting server. makesure to load correct libray based on your php version see here windows.php.net/downloads/pecl/snaps/printer/0.1.0-dev for more dlls for several php versions.
I have xampp and php_printer.dll loaded into C:\xampp\php\ext folder.. then I write the printer.default_printer=PHP_INI_ALL extension=php_printer.dll at the end of php.ini file.. but error remaining same
hey i configure this dll. when i run this code then no error occured. But print not happening

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.