abc
abc

Reputation: 2437

PDF-Print from C#-Program with Ghostscript on specific tray

in my current software I'm creating pdf-files and printing them out with ghostscript like this:

...
string[] printParams = new string[] {
"-q",
"-sDEVICE=mswinpr2",
"-sPAPERSIZE=a4",
"-dNOPAUSE",
"-dNoCancel",
"-dBATCH",
"-dDuplex",
string.Format(@"-sOutputFile=""\\spool\{0}""", printerName),
string.Format(@"""{0}""", filename)
...
var p = new Process();
p.StartInfo.FileName = this.ghostScriptExePath;
p.StartInfo.Arguments = string.Join(" ", printParams);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
...

So far it works just fine and prints out on the specified printer.

My problem is, that I want to print out my pdf-document from a specific paper tray in some cases.

Can this be achieved with ghostscript?

I know, that I can add a printer twice to my installed devices, once with tray 1 and once with tray 2, but this would be a lot of effort to configure on all effected client-PCs.

Thank you for your help!

Karl

Upvotes: 3

Views: 2465

Answers (2)

HABJAN
HABJAN

Reputation: 9338

Just an idea for which I'm sure it will work:

Since you are using Ghostscript, you can rasterize your PDF's to images and then print images by using PrintDocument class already built in the .NET framework. This way you can choose which tray to use by setting PageSettings.PaperSource to a different tray. Take a look at this example: How to select different tray for PrintDocument with C#

For simpler Ghostscript usage from you C# code, you can use Ghostscript.NET, a managed wrapper for the Ghostscript library. Take a look at this sample on how to rasterize PDF to image: GhostscriptRasterizer Sample.

Ghostscript.NET is also available via NuGet: http://www.nuget.org/packages/Ghostscript.NET/

If you want to do everything by using Ghostscript, you could convert your PDF's to Postscript, parse that Postscript files, modify them by adding tray select code and then print Postscript files.

Upvotes: 2

KenS
KenS

Reputation: 31139

Basically, no. The mswinprs2 device doesn't support any significant amount of configuration, beyond the media size and colour depth. You can have the device put up a print dialog to allow you to change the settings interactively.

Alternatively you could add it, you'd need to add a switch to specify which paper tray you want, and then alter the DEVMODE structure before the createDC creates the device context.

Upvotes: 1

Related Questions