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

in my current software i create pdfs and print them using 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 fine and prints to the specified printer.

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

Can this be done with ghostscript?

I know that I can add the printer twice to my installed devices, once with Tray 1 and once with Tray 2, but that would be a lot of effort to set up on all processed client PCs.

Thanks for your help!

Charles

+3


source to share


2 answers


Just an idea for which I am sure this will work:

Since you are using Ghostscript , you can rasterize the PDF to images and then print the images using the PrintDocument class already built into 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 choose a different tray for a PrintDocument from C #

For easier use of Ghostscript from your C # code, you can use Ghostscript.NET , a managed wrapper for the Ghostscript Library. Take a look at this example of how to rasterize a PDF for an image: GhostscriptRasterizer example .



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

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

+2


source


In principle, no. Mswinprs2 does not support any significant amount of configuration beyond media size and color depth. You can install a print dialog box on the device that allows you to interactively change settings.



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

+1


source







All Articles