Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Slightly complicated printing question

I just got done writing this PDF faxing application with old-school win32.  It works great, except for one small problem.  When I call the FaxSendDocument function, it pops up an Adobe Acrobat window and prints the PDF to the fax printer.  The problem is, it doesn't close it. 

Now, what I think is going on is that the win32 api is calling Acrobat in such a way as to say "Hey, print this document for me."  I'd like it if Acrobat would print the document automatically without mucking about with all of these dialog boxes. 

I have found a program with a command line interface (AutoPrint, from www.acrobotics.net) which will silently print PDFs to the default printer.  I'd like to write a little .net wrapper around this thing, and make my .net application be the default program for PDFs on the fax server.  I think that would work, but I'm not sure.

So here are my questions:

1.  How can you start a program just to have it print a document?  For instance, what if I had a word document that I wanted to print from my program?  What's the easiest way to do it? 

2.  What does that look like from the called program's standpoint?  For instance, if I defined my own document type, .foo, and registered my application as being the default program to handle .foo files, what happens if someone calls me to print a .foo document?

3.  Of course, it would be nice if there was a reasonably priced application I could use that would print (without bringing up any dialog boxes!) PDFs if I set it as the default application for PDFs.  I haven't been able to find any applications that actually do this, but I'm open to suggestions.

I've been googling and searching on MSDN for the answers to some of these printing questions, but I just don't know what to search for.

Thanks.

John Wilson
Tuesday, April 13, 2004

On my machine, if I look at the ".pdf" entry in the HKEY_CLASSES_ROOT section of the registry, the (Default) entry value is "AcroExch.Document"

So if I look in the "AcroExch.Document" entry in the HKEY_CLASSES_ROOT section of the registry, there are "print" and "printto" sections. Under each "print" and "printto" sections is a "command" section, which defines the command-line parameter required to invoke the application to print the document. The command-line in the "print" section is used to print to the default printer, and the command-line in the "printto" section is used to print on the specified, named, non-default printer.

> For instance, what if I had a word document that I wanted to print from my program?  What's the easiest way to do it?

The 'easiest' way if you don't know what kind of application services this document might be to use the ShellExecuteEx API with "print" as the 'verb'. Doing this I think causes the O/S (the 'shell') to look in the registry entries I mentioned above. There are other, application-specific ways to print: for example, you may discover that Word supports COM and DDE interfaces, and use those interfaces to tell it to print.

> For instance, if I defined my own document type, .foo, and registered my application as being the default program to handle .foo files, what happens if someone calls me to print a .foo document?

You'll see it on your command-line, or your COM or DDE interface. If you see this on your command-line and you're especially well-behaved, then you'll understand that you were launched only to print a document and you'll voluntarily exit after you've done printing it.

> Of course, it would be nice if there was a reasonably priced application I could use that would print (without bringing up any dialog boxes!) PDFs if I set it as the default application for PDFs.  I haven't been able to find any applications that actually do this, but I'm open to suggestions.

I think that when we implemented this (when writing a fax server and printer driver) we killed Acrobat at the end of the print job. Various caveats apply here (e.g. we were running on a dedicated server, so not interfering with an end-user's applications).

Christopher Wells
Tuesday, April 13, 2004

Ah, that is one of the problems with the original application:  the way that it closes the acrobat windows causes Acrobat to completely freak out about ten percent of the time.  By freak out I mean that acrobat refuses to work without rebooting, so our production server gets rebooted about once a day with a normal fax load. 

(The original was written in VB6; mine is a rewrite without such stupidity as calling a stored procedure, generating an XML document with fax parameters, sending the XML to an XML parsing function, which generated a collection that was passed to another function which did some filtering of the data which it received... at that point I gave up on it.  I replaced all that crap with one stored procedure.)

Anyway, that info looks like it will really help out; I'll see what I can get working tomorrow.

Thank you kindly.

John Wilson
Tuesday, April 13, 2004

Try this:

http://forum.planetpdf.com/wb/default.asp?action=9&read=36960&fid=52#110542

chicks
Thursday, April 29, 2004

*  Recent Topics

*  Fog Creek Home