Re: PDF printing under windows.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tg-php@xxxxxxxxxxxxxxxxxxxxxx wrote:

Two (and a half) things:

1. Even though DOS/Windows machines don't have, specifically, /dev/printer or /dev/lpr or whatever the *nix specific is, it does have a LPTx: device

According to the page listed below, it may be possible to do:
copy /b filename LPTx

The /b indicates it's a binary file.  How it'd handle PDF fonts and such, I'm not sure, but I know that some printers can decode PDF's internally so that'd work out great.

2. Second point... If all you need is a simple print function and you have exec() privs, why not try to find a DOS based printing solution.  The copy command above was mentioned on this page:
http://www.lerup.com/printfile/

It says it works with Windows 3.1 to XP.  And it even works with command line options:

"PrintFile also works well with command line (DOS) programs. It has several command line options and can read data from command line standard input, e.g. a command line pipe. A command like:
dir | prfile32"

So I guess it sets up it's own print device that you can pipe to.

And finally... the half a point.  All of this may not be necessary because you can configure Windows printers to support DOS (although I havn't done this in ages, I assume you still can in XP) so in theory the normal DOS "print" command would pipe through Windows drivers and print handling to the printer of choice.


So in general, there's probably zero need to use COM to print.  One of these options should pipe the file through Windows which in turn, could possibly send it through the proper printing method.   If not, you might be able to look in your registry and find the right-click "Print..." option and see if it's something you can execute from command line.

Ok, I know this email's too long already, but I know someone's going to say "How do you do that?"  So here's the 50 cent tour:

1. Pull up "regedit"
2. Search for the file extension ".pdf"
3. Make note of the "(Default)" value, in this case "AcroExch.Document" (I think this is specific to having the full Acrobat installed)
3. Below the area where all the file extensions are in HKEY_CLASSES_ROOT there are the actual named app section (that way, ".gif" and ".jpg" can both point to Photoshop.document" or something.. get it?)  So search for "AcroExch.Document" in this case
4. Expand that tree and look for "shell". These are all the things that show up on your right-click menu.  In this case, we have a "print" section. Under each of these entries, there should be (but sometimes not) a "command" branch.  This is what's run when you select that option from the right-click menu.  And voila! We find that the command to use Acrobat to print (which can be executed from command line on a Windows machine) is:
"C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe" /p /h "%1"

Substituting the %1 for the filename.


Using that command line in a php exec() call should exactly simulate selecting right-click PRINT on
The problem there is that you end up having a load of acrobat.exe's
open. It will print, but it won't shutdown the app afterwards. So
automate printing of invoices maynot be a good idea :-)
I think I'll just install a linux box and use CUPS :-)

Dave.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux