This project is read-only.

GhostscriptProcessor with pdfwrite fails to write pdf

Sep 19, 2014 at 10:05 AM

Im trying to use the GS.Net library to reduce a load of PDF files programmatically. It finds the PDF (it has the correct number of pages but no new pdf is written to the dir). What am i dooing wrong? I get no exceptions.

    internal class Program
        private static void Main(string[] args)
            const string InputFile = @"E:\OPD\038612_2_org.pdf";
            const string OutputFIle = @"E:\OPD\038612_2_org_ebook-code_1.pdf";

            var gsVersionInfo = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
            using (var gsProcessor = new GhostscriptProcessor(gsVersionInfo, true))
                gsProcessor.Processing += ProcessorProcessing;
                var switches = GetGsSwitches(InputFile, OutputFIle);
                gsProcessor.StartProcessing(switches.ToArray(), null);

        private static List<string> GetGsSwitches(string inputFile, string outputFile)
            var switches = new List<string>
                                   @"-sOutputFile=" + outputFile,

            return switches;

        static void ProcessorProcessing(object sender, GhostscriptProcessorProcessingEventArgs e)
            Console.WriteLine(e.CurrentPage + " / " + e.CurrentPage);
GS console line used, which reduces the original PDF and saves the new PDF to disk:
"C:\Program Files (x86)\gs\gs9.14\bin\gswin32c" -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile=E:\OPD\038612_2_org_ebook_code_2.pdf E:\OPD\038612_2_org.pdf

Anyone got a tip?

Sep 19, 2014 at 11:08 AM
Great, i found the solution myself. The first switch is ignored, probably used for the gs call, so the pdfwrite was actually never invoked.

So I added a "-empty" switch to the list as first item, and it works.

Oct 3, 2014 at 8:52 AM

Sorry for the delay.

Yep, I should note somewhere that the first parameter is ignored by the Ghostscript library.

I'm glad you figure that out.