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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With