1 Replies - 160 Views - Last Post: 19 November 2019 - 07:15 AM Rate Topic: -----

#1 KC10513   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 13-October 17

Ghostscript PDF Black&White and Page range

Posted 19 November 2019 - 02:50 AM

I'm coding a PDF printer that will be running on a server. Basically i have a pdf file(color or black and white) that is already created then we tell ghostscript to send the file to a physical printer and the output should either be b&w/color based on the parameters selected + many other fields we can set such as page range, number of copies etc...
here's the method i use but am failing to print b&w and also setting the page range
public static void printPDF(string filename, string printerName, int numberofcopies, bool pagerange, int frompage, int topage)
        {
            //REF:https://www.ghostscript.com/doc/current/Use.htm#Output_resolution
            try
            {
                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("-dNoCancel");
                    //switches.Add("-dPDFFitPage");
                    if (pagerange)
                        switches.Add("-sPageList=" + frompage + "-" + topage);
                    switches.Add("-dNumCopies=" + numberofcopies);
                    switches.Add("-sColorConversionStrategy=Gray");
                    switches.Add("-sProcessColorModel=DeviceGray");
                    switches.Add("-dOverrideICC");
                    switches.Add("-sDEVICE=mswinpr2");
                    //parameters.Add("-sDEVICE=pdfwrite");
                    //switches.Add(Convert.ToString("-sOutputFile=%printer%") + printerName);
                    switches.Add(@"-sOutputFile=""%printer%" + printerName + "\"");
                    switches.Add(" - f");
                    switches.Add(filename);
                    
                    processor.Process(switches.ToArray(), null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }


So i ask is there something wrong with my code or am i missing a switch somewhere.

Is This A Good Question/Topic? 0
  • +

Replies To: Ghostscript PDF Black&White and Page range

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7139
  • View blog
  • Posts: 24,245
  • Joined: 05-May 12

Re: Ghostscript PDF Black&White and Page range

Posted 19 November 2019 - 07:15 AM

From the C# perspective, nothing looks wrong there.

From the GhostScript perspective, I have no idea.

Your question above is essentially a "how to use GhostScript" question rather than a C# question.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1