0

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);
        }
    }
Crumblenautjs
  • 169
  • 1
  • 3
  • 24

1 Answers1

1

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.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Hey KenS, thanks again for your support with GS. I believe my issue revolves more around the data that I'm trying to print, than GS or GhostScript.NET. – Crumblenautjs Feb 09 '17 at 15:54
  • 1
    Hmm, well that's possible certainly. I'd still try it from the command line. If you think its the input that's doubtful, just run "gswin32 " and that will render to the display. Should at least tell you if the input file is OK. – KenS Feb 09 '17 at 17:07
  • I'm using the gswin32 "C:\TEMP\report.jpg" command line, but I'm getting an operand error. I have the file I'd like to print stored in that file. What's the correct syntax to try to print the file located at that path? – Crumblenautjs Feb 09 '17 at 21:34
  • 1
    You can't simply send a JPEG file to Ghostscript. Ghostscript will accept PostScript and PDF as input, not JPEG. Are you trying to print a JPEG file ? Your title says you are trying to print a PDF..... – KenS Feb 10 '17 at 08:20
  • 1
    I switched it back to printing PDF bytes, and what do you know? It worked:) Thank you Ken and JHabjan. – Crumblenautjs Feb 10 '17 at 15:28