Print PDF using GhostScript

前端 未结 4 1604
一个人的身影
一个人的身影 2021-02-06 16:21

I am in need of your support on the following issue since its pulling me for a while. We have a small c# utility, which print given PDF using Gho

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 16:50

    You could use GSPRINT.

    I've managed to make it work by only copying gsprint.exe/gswin64c.exe/gsdll64.dll in a directory and launch it from there.

    sample code :

        // This uses gsprint (mind the paths)
        private const string gsPrintExecutable = @"C:\gs\gsprint.exe";
        private const string gsExecutable = @"C:\gs\gswin64c.exe";
    
        string pdfPath = @"C:\myShinyPDF.PDF"
        string printerName = "MY PRINTER";
    
    
        string processArgs = string.Format("-ghostscript \"{0}\" -copies=1 -all -printer \"{1}\" \"{2}\"", gsExecutable, printerName, pdfPath );
    
                var gsProcessInfo = new ProcessStartInfo
                                        {
                                            WindowStyle = ProcessWindowStyle.Hidden,
                                            FileName = gsPrintExecutable ,
                                            Arguments = processArgs
                                        };
                using (var gsProcess = Process.Start(gsProcessInfo))
                {
    
                    gsProcess.WaitForExit();
    
                }
    

提交回复
热议问题