Print PDF using GhostScript

前端 未结 4 1596
一个人的身影
一个人的身影 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:33

    Answer - UPDATE 16/12/2013

    I was managed to get it fixed and wanted to enclose the working solution if it help others. Special thanks to 'KenS' since he spent lot of time to guide me.

    To summarize, I finally decided to use GSView along with GhostScript to print PDF to bypass Adobe. The core logic is given below;

     //PrintParamter is a custom data structure to capture file related info
    private void PrintDocument(PrintParamter fs, string printerName = null)
            {
                if (!File.Exists(fs.FullyQualifiedName)) return;
    
                var filename = fs.FullyQualifiedName ?? string.Empty;
                printerName = printerName ?? GetDefaultPrinter(); //get your printer here
    
                var processArgs = string.Format("-dAutoRotatePages=/All -dNOPAUSE -dBATCH -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dEmbedAllFonts=true -dSubsetFonts=true -dPDFSETTINGS=/prepress -dNOPLATFONTS -sFONTPATH=\"C:\\Program Files\\gs\\gs9.10\\fonts\" -noquery -dNumCopies=1 -all -colour -printer \"{0}\" \"{1}\"", printerName, filename);
                try
                {
    
                    var gsProcessInfo = new ProcessStartInfo
                                            {
                                                WindowStyle = ProcessWindowStyle.Hidden,
                                                FileName = gsViewEXEInstallationLocation,
                                                Arguments = processArgs
                                            };
                    using (var gsProcess = Process.Start(gsProcessInfo))
                    {
    
                        gsProcess.WaitForExit();
    
                    }
    
            }
    

提交回复
热议问题