PHP to print to a server side printer

I am trying to use PHP to print to a server side printer. I have found similar example code that mostly all use the same API’s functions in order to do this task. When I ran it on my server to test the code it was saying “PHP Fatal error: Call to undefined function printer_open()”. So I found at least three different versions of the php_printer.DLL’s for this printer function and tried them all separately . I did some more research and looking into the apache server error log found this warning

PHP Warning: PHP Startup: Unable to load dynamic library ‘ext\php_printer.dll’ - The specified module could not be found.\r\n in Unknown on line 0

From this found some Bing search results that said that the reason it is not loading when apache starts up is because it is depend on other libraries. If this is true I have not as yet been able to find which library DLL’s these are and where to get them. This is what I need help with first to basically know if it is not depended then why is the PHP warning being thrown or what library’s do I need. Thanks for any help
zac

I am running a wampserver2.2
Apache 2.4.2
PHP 5.4.3
OS : windows 7 64 bit
Added to the php.ini file
extension=php_printer.dll
and no errors in the php log

also I did restarted the server each time I change the php.ini file or when I put a new DLL in the ext\ directory

I even put the path to the wamp DLL’s “...\ext\” in the environment variables for windows, as a shoot in the dark . :frowning:

Example code

[php]<?php
$lipsum = “test print”;//file_get_contents(‘lipsum.txt’);
phpinfo();/not displaying the Module for the printer/

/* open a connection to the printer */
$printer = printer_open("Microsoft XPS Document Writer");/*stops here with error*/

/* write the text to the print job */
printer_write($printer, $lipsum);

/* close the connection */
printer_close($printer);

?>[/php]

I’m not seeing many examples of people that aren’t having problems with the code. What is your end goal?

I was needing to print from a file that file would be an excel type spread sheet . I was going to parse line by line and each line it would print to the printer. The lines would have client names ,addresses which would then be sent to the printer where they are put on envelopes. I am sure there is other ways to do this but I need it to use php. I am not to worry about security since this will only be run in-house where I use it.

Thanks
zac

If you don’t have a reason to print it automatically, you could just create the file then print from excel.

I am sure there is other ways to do this but I need it to use php.

Why do you need it to use PHP when there are other ways of dealing with it that are simpler. Generally, the client script would handle the print queue. A server is generally not hooked to a monitor, much less a printer, which is why this is not a normal task.

first thanks for responding to this question .

now I did not fully realize that excel had some kind of functionality that allow you to print each line of an excel spreadsheet and do it hundreds if not thousands of time to the printer. where each time or rather each line would be printed on an envelope. That being said the reason for me using php is that I am familiar with it and want to understand more about it even if it means doing things the hard way. I understand that php is on the serverside and that was where I was looking to print I was going to run the sever on my laptop and print from there. I did not need to print to the client side and how I understood it that would not be possible since php does not run on the client side.

I believe I found the possible root to the problem it was that the DLL files that had the library and functions for the printer script where not recognized by the main php application that runs on the server version 5.4.3 and the php_printer.dll was either old or newer . anyway this is what should work if I did not have any dll not being recognized or some other error problem.

this is a link I need to have 10 post to make this link

now the following seems to be the closest I have come to the problem to be solved

this is a link I need to have 10 post to make this link

https://community.apachefriends.org/f/viewtopic.php?t=53348&p=204590

now just so you know I am all ways open to new ways to solve a problem but since I have submitted this question my wife work has already hand writhen a few thousands of these customer letters and for the time is not needing this one time serious. But I would ,even if it does not make much more since other than just to have done it ,like to know how to do it with php just to have closer

thanks
zac

I am going to assume that you really don’t need it to print automatically. If you are printing on envelopes, you have to hand load the printer, correct?

I would have the address information in a database, but you could just have a single page that would open and on opening would open the printer dialog using this,
[php]
[/php]

Not ideal if you actually need it to run on a schedule, but if someone does an action, such as opening the page, it would work. The rest would need to be handled by css rules, if you were to use html for the layout.

Thanks and this is cool but a couple of thing. I need to print several hundred if not a few thousand envelopes and the envelopes would be in the printer so as soon as one prints another would start to print. another thing is that someone would have to click to confirm the print for each envelope. but this may work in a pinch. But I am still looking just out of learning curiosity how to get it to print use the php function from the posted question.

Thanks
zac

They can all be queued in one print job, the printer will wait while you load the next envelope.

Sponsor our Newsletter | Privacy Policy | Terms of Service