Re: PDF printing under windows.

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

 



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 a PDF file.


Crossposting this to PHP-Win for their benefit too since this is more Windows related than PHP General.

I see lots of ways to potentially solve this problem without using COM.

I loved messing with COM (with or without PHP) for a while, but it's not a great general solution to things unless you absolutely HAVE to control the app (which is very cool and slick sometimes, but not for something as simple as printing).

Hope this gives you some new avenues to persue.  Best of luck!

-TG

= = = Original message = = =

Richard Lynch wrote:

>On Mon, October 24, 2005 1:48 pm, Dave Lists wrote:
>  
>
>>I'm generating PDFs under windows using PDFlib and all is easy. What I
>>am wondering though, and google reveals nothing usefull, can I print
>>the
>>PDF to a network printer from windows? I'm presuming to print the file
>>I
>>would ahve to use COM and open it under Acrobat? Anyone done this
>>before
>>and have any pointers? I'm printing out invoices and what to automate
>>the task.
>>    
>>
>
>If, for some weird reason, you want to allow the user (authenticated,
>logged in, trusted) to print to a networked computer on the WEB
>SERVER, then your best bet is probably to figure out how to print that
>PDF from MS-DOS and then to use http://php.net/exec to print it, I
>would guess...
>  
>
 It's from a cli PHP install on a local machine :-)

>You might be able to use PHP to open up a COM object to convince
>Adobe/Windows/whatever to print...
>  
>
 COM makes me want to cry ;-) At the moment I'm trying to convince 
OpenOffiice it wants to play with PHP and COM.
 I have tried to exec print on the windows box but that just hung.

>If it was a Un*x server, you'd just send the document to lpr or CUPS
>or something, and be done with it, probably in a half-hour of work,
>even allowing for a protracted battle with file/exec permissions.
>
>  
>
I'm not sure I could just fire a PDF at lpr, but no doubt it would be 
much easier under Unix :-)

Dave.


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
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