print PDF to physical printer
Moderator: General Moderators
print PDF to physical printer
Is there a way that currently works in PHP 5 on Windows 7 to print a PDF to a physical printer from a PHP script?
I've read a great many suggestions to use AcroRd32.exe. This no longer works, and was never a workable solution since it apparently leaves Reader open. It currently doesn't work on WIndows 7 at all. Not even from the command line. Reader can no longer read a path name from the command line:
"The system cannot find the path specified"
I get this even when I am sitting in the document directory so I don't have to specify a path. I do have Reader associated with PDF files, and it does come up when I double-click PDFs in explorer.
I also had to put reader in my Path because spaces in the executable path give me
"C:\Program" is not recognized as an internal or external command..."
or
"The filename, directory name, or volume label syntax is incorrect"
if I put it in single quotes.
In short, none of the examples I found work syntactically.
I also looked into the Printer commands in PHP. They rely on a DLL that is no longer maintained, and for which there is not a 64-bit build.
So, is it even possible to print PDFs to a physical printer in a PHP script? Or even from the command line?
I've read a great many suggestions to use AcroRd32.exe. This no longer works, and was never a workable solution since it apparently leaves Reader open. It currently doesn't work on WIndows 7 at all. Not even from the command line. Reader can no longer read a path name from the command line:
"The system cannot find the path specified"
I get this even when I am sitting in the document directory so I don't have to specify a path. I do have Reader associated with PDF files, and it does come up when I double-click PDFs in explorer.
I also had to put reader in my Path because spaces in the executable path give me
"C:\Program" is not recognized as an internal or external command..."
or
"The filename, directory name, or volume label syntax is incorrect"
if I put it in single quotes.
In short, none of the examples I found work syntactically.
I also looked into the Printer commands in PHP. They rely on a DLL that is no longer maintained, and for which there is not a 64-bit build.
So, is it even possible to print PDFs to a physical printer in a PHP script? Or even from the command line?
Re: print PDF to physical printer
No.amyhughes wrote:So, is it even possible to print PDFs to a physical printer in a PHP script? Or even from the command line?
Re: print PDF to physical printer
Here is one of many nearly identical non-working examples I've found on the net:
shell_exec("'C:\Program Files\Adobe\Acrobat 6.0\Reader\acrord32.exe' /t c:\test1.pdf \\myserver\myprinter");
As I mentioned, I eliminated the need for spaces in the executable path by includung reader in my search path:
shell_exec("acrord32.exe /t c:\test1.pdf \\amy-laptop\hp2727");
and eliminated the path to the file by running this from the same directory as the file:
shell_exec("acrord32.exe /t test1.pdf \\amy-laptop\hp2727");
and eliminated the printer just to see what that'll do (answer:nothing)
shell_exec("acrord32.exe /t test1.pdf");
and run it from the command prompt
acrord32.exe /t test1.pdf
and tried without arguments at all
acrord32.exe
This works. It launches reader with no document. So, the path thing is working. It's the only thing that's working.
shell_exec("'C:\Program Files\Adobe\Acrobat 6.0\Reader\acrord32.exe' /t c:\test1.pdf \\myserver\myprinter");
As I mentioned, I eliminated the need for spaces in the executable path by includung reader in my search path:
shell_exec("acrord32.exe /t c:\test1.pdf \\amy-laptop\hp2727");
and eliminated the path to the file by running this from the same directory as the file:
shell_exec("acrord32.exe /t test1.pdf \\amy-laptop\hp2727");
and eliminated the printer just to see what that'll do (answer:nothing)
shell_exec("acrord32.exe /t test1.pdf");
and run it from the command prompt
acrord32.exe /t test1.pdf
and tried without arguments at all
acrord32.exe
This works. It launches reader with no document. So, the path thing is working. It's the only thing that's working.
Re: print PDF to physical printer
Seriously? Is there a way to print anything at all from a PHP script?Celauran wrote:No.amyhughes wrote:So, is it even possible to print PDFs to a physical printer in a PHP script? Or even from the command line?
Re: print PDF to physical printer
No.amyhughes wrote:Seriously? Is there a way to print anything at all from a PHP script?Celauran wrote:No.amyhughes wrote:So, is it even possible to print PDFs to a physical printer in a PHP script? Or even from the command line?
Closest you can come is to display on screen and use JavaScript's window.print.
Re: print PDF to physical printer
This isn't an interactive script, or a web page. It's a script that periodically polls for available data through a web API, and it's supposed to leave prints on the printer in the morning.
Thanks,
Amy
Thanks,
Amy
Re: print PDF to physical printer
PHP probably isn't the right language, then.
Re: print PDF to physical printer
Here's what works from the command line:
put the executable path in double quotes, and use /p /h and the default printer
"C:\Program Files\Adobe\Acrobat 6.0\Reader\acrord32.exe" /p /h test1.pdf
It also seems to work from shell_exec
put the executable path in double quotes, and use /p /h and the default printer
"C:\Program Files\Adobe\Acrobat 6.0\Reader\acrord32.exe" /p /h test1.pdf
It also seems to work from shell_exec
Re: print PDF to physical printer
assuming that you are talking of an INTRANET scenario where server/clients/printer are in the same network then Yes... it is possible... sure Celauran was thinking in the INTERNET scenario.. and for that he is correct.
Instead of Acrobat I do use PDFExchange viewer... and more or less I do something like this:
Instead of Acrobat I do use PDFExchange viewer... and more or less I do something like this:
Code: Select all
// Define Main File Path, Printer and Printer command
$filepath = $_SERVER['DOCUMENT_ROOT']."/myfolder/"; // Path to the file that you want to print
$printer = "\\\\MyPrintServer\\yourprinternamehere"; // absolute UNC path to your printer .. note the use of backslashes to escape the necesary ones
$printercmd = "PDFXCview.exe /print:printer=\"$printer\" "; // line will change depending of what viewer you are using to print
and down below my code
$printcmd = $printercmd . " $file"; // here I do add the file to print
exec($printcmd); Re: print PDF to physical printer
I spent a couple weeks researching this as well, and came up empty. On one hand it is surprising that simply printing a file is not possible. On the other hand it does make sense - PHP is a language for building web pages, not printing files on a server.
You may be able to open a socket connection directly to the printer and then send the file data. You don't get to set any properties (ie: finishing, double-sided, etc) though.
I did look into a PERL solution, but I gave up when I had to install PERL.
A Linux server will work, provided the printer vendor provides drivers for Linux. I ended up having to use OS X & CUPS/lpr.
You may be able to open a socket connection directly to the printer and then send the file data. You don't get to set any properties (ie: finishing, double-sided, etc) though.
I did look into a PERL solution, but I gave up when I had to install PERL.
A Linux server will work, provided the printer vendor provides drivers for Linux. I ended up having to use OS X & CUPS/lpr.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: print PDF to physical printer
As soon as they answer me a licensing question I hope to use this instead of Reader...
http://www.coolutils.com/TotalPDFPrinter
It has control over printer settings right from the command line, and works like a charm from shell_exec.
http://www.coolutils.com/TotalPDFPrinter
It has control over printer settings right from the command line, and works like a charm from shell_exec.
Re: print PDF to physical printer
well... PDFExchange viewer is free... and printing in the way that I did describe previously is something that my users do everyday... and they print a lot...