Crumblenautjs
Crumblenautjs

Reputation: 169

Trying to print PDF using GhostScript

I'm trying to print a PDF document using ghostscript. I'm using the GHOSTPRINT.NET wrapper. I have been able to achieve sending output to the printer, however it remains stuck in spooling status. Not sure if it has to do with the switches I'm using or the file itself.. Any help would be appreciated. Here's the code:

 public static void PrintFormPdfData(byte[] formPdfData, string printer)
    {
        string tempFile;

        tempFile = Path.GetTempFileName();

        using (FileStream fs = new FileStream(tempFile, FileMode.Create))
        {
            fs.Write(formPdfData, 0, formPdfData.Length);
            fs.Flush();
        }
        using (GhostscriptProcessor processor = new GhostscriptProcessor())
        {
            List<string> switches = new List<string>();
            switches.Add("-empty");
            switches.Add("-dPrinted");
            switches.Add("-dBATCH");
            switches.Add("-dNOPAUSE");
            switches.Add("-dNOSAFER");
            switches.Add("-dNumCopies=1");
            switches.Add("-sDEVICE=mswinpr2");
            switches.Add("-sOutputFile=%printer%" + printer);
            switches.Add("-f");
            switches.Add(tempFile);

            processor.StartProcessing(switches.ToArray(), null);
        }
    }

Upvotes: 0

Views: 2174

Answers (1)

KenS
KenS

Reputation: 31139

If I were you I would start by using the command shell and run Ghostscript from the command line.

If that doesn't work then we can go further, but at the moment you are essentially asking for help on 2 different components simultaneously, Ghostscript and the Ghostscript.NET C# wrapper. Ideally you need to work out where your problem is first, if it works from the command shell, then its something to do with Ghostscript.NET. If it doesn't, then its something to do with Ghostscript.

Note that the trailing '-f' there might be part of the problem. You don't need that unless you :

a) Used the -c switch to introduce PostScript and b) Intend to follow it with further options.

Upvotes: 1

Related Questions