Re: [PHP] PDF printing under windows.

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

 



David.. I think I accidentally deleted your last message, but I believe you said something about Acrobat not closing after it gets done printing.  Here are a few thoughts:

1. If you right click on something and select "print" and it performs the command line action listed in the registry as mentioned below, it SHOULD exit when done printing. If it doesn't, it could be an app issue.

2. If you use COM and app doesn't close properly, you might want to look at the app "Close" as well as "Quit" methods.  If I recall, you can do one, or the other, but an instance of the app may still hover invisible in the background.  I remember using both (in a certain order.. reversing the order made it so the app still stayed loaded.. the correct order though made sure the app closed properly).

3. If a certain file type (like say Excel files for instance) requires a specific app to interpret it's data for output, then you kind of can't get around loading the app in order to print it.  Unless you can find a smaller view/print-only app that's made for handling that app's data files.   In the case of PDF, if you're lucky then your printer knows how to decode them and you might get away with piping the raw binary file directly to the print device (LPTx in the case of DOS/Windows.. where "x" is of course the number of the printer device.  Might have to mount the printer to that port though or do the DOS printer config in Windows).   The printer needs intelligible data from the PC if it doesn't natively know how to handle the file.  So again, you need the real app or a reader type app to load in order to send the printer proper data.


If you get the print command line out of the registry as listed below, then it SHOULD exit properly.  If not, it's a problem with the app and not with your code.  Try performing the CLI command in a command prompt and see if the app exits properly before doing it in PHP.    Something as common (and an open standard) like PDF, you should be able to find other DOS and/or Windows apps that'll print it, but you'll probably still have to use the command line and exec() call of some kind, unless you use COM which is overly complicated and burdensome in my opinion.

-TG

= = = Original message = = =

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 Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux