views:

690

answers:

2

We have large IBM Infoprint printers. I need to read a bunch of PDF files off a database, merge them together, and send it to one of these printers. I need to be able to specify many options such as what tray to use, with/without staple, etc. All of these options can be manually set when I try to print something off my computer (via the advanced print driver preferences), so I am certain that these can also be set programmatically. How can I do this in .NET (Visual Basic)?

+2  A: 

You'll want to examine the System.Drawing.Printing namespace. Specifically, the settings you're looking for will be in the PrinterSettings class. A primer on GDI printing in .NET is a little out of the scope of this site, but many are available on the web. I'm hesitant to post a link to a particular article, since many examples are lacking in both depth and best-practices adherance. I'll do some additional looking and see if I can find one that's a good starting point.

Edit

Most common printer settings (duplex, color, etc.) are implemented in the PrinterSettings and PageSettings classes. For "extra" information that isn't part of the standard Windows printing API, you'll have to use a DEVMODE structure. For more information (and a blog that appears to be doing exactly what you want to do), check out this article.

Adam Robinson
How does it know what options each printer provides? I doubt this class has been extended for every single printer ever produced!
Josh Stodola
@Josh: I believe the print driver takes care of that for you. Windows just uses its standard interfaces to create the print job so if you send it something that it cannot do, the driver should just ignore it.
Austin Salonen
DEVMODE is not working for me. It says it is not defined.
Josh Stodola
I am trying to dump the current DEVMODE settings using the example provided by your link, but it says DEVMODE is not defined (among other things, like the 2008Flyer). How can I resolve this?
Josh Stodola
See the link I placed on the DEVMODE above. It takes you to pinvoke.net where you can find the definition for the structure.
Adam Robinson
So I need to define it myself? Sorry, this is very foreign to me!
Josh Stodola
Yes. When using a structure that is part of an external API (such as this one), you have to "redefine" the structure in your .NET code so that it matches the structure that a function expects.
Adam Robinson
+1  A: 

You can use iTextSharp to stitch PDF files together (http://itextsharp.sourceforge.net/) And you can use GhostScript (http://www.ghostscript.com/) to send PDF files directly to a Named Printer.

Mark Redman
-1 I have no problems merging. And I need to send this to the printer using .NET, not an interpreted scripting language written in C.
Josh Stodola
In order to send a PDF to a printer, its requires something to Interpret the PDF and write it out to the printer. The Interpretation is done through GhostScript, you can use .NET to instruct GhostScript to do this.
Mark Redman
I will be interested to see your solution. I have a C# GhostScript Wrapper you can use to do this if you need it, Contact Details at: http://redmanscave.blogspot.com/
Mark Redman
I had to move onto another project for a while, but I still have to tackle this issue. I will certainly let you know what I come up with!
Josh Stodola
@Mark Redman: Quite a few of the larger printer manufacturers have embedded PDF renderers, and thus accept PDF as a valid PDL just like PCL or PostScript. Well, at least I can say that about the ones I program.
dreamlax