简体   繁体   中英

PHP printer_write PDF file?

I understand that you can use the printer_write function to print out text with PHP on a printer attached to the server. But can you use this function to print a pdf file that is located on the server?

Thanks in advance!

Yes, it's possible but it's quite a hassle. We recently built an application that needed to print labels for customers from PHP. We decided to go with a Windows server and a printer that had its own software for printing.

This is the code we ended up with for printing the generated label:

system('"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" /p "C:\www\pdf\label.pdf"');

Please note that this is a very specific solution for a specific printer and platform. Similar solutions for printers with proper Linux drivers or other printers for Windows should work fine providing they have a similar way of processing a file through the command line.

It took alot of tinkering but I finally came up with:

exec("\"C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32.exe\" /t \"C:\\PathToPDF.pdf");

I couldn't get Foxit to use a smaller label size with the Brother printer, it would default to a 4x6" label and result in errors. (Using Brother QL-1060N). --Though, I must note that it would work fine with the default label size.

I got around this using Adobe Reader 9 and leaving it always open on the server computer, with appropriate print settings. I use 9 because for some reason Adobe Reader X, on every label after the first one, will be 1 ACSII character off. (EG. 1=2, 8=9, =!).

Thanks Karl. I hope this is of great use to future readers! =)

Happy coding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM