We use have an winform app, which uses AdobeReader to print files from a specific directory. Recently, we re-factored this app whereby replacing AdobeReader with Ghost script. AdobeReader prints document properly (as per document format such as font, alignment, line spacing etc). But Ghost script print the document without complying the document format. Any advise ?

FYI: PrintParamter is a custom type which enclose the details of file name/path to print, GetDefaultPrinter() is a helper method which return default printer.

private void PrintDocument(PrintParamter fs, string printerName = null, bool isPortrait = true,
                                   int noOfCopies = 1, bool printInGrey = false)
        {
            var filename = fs.FullyQualifiedName ?? string.Empty;
            printerName = printerName ?? GetDefaultPrinter();
            var processArgs = string.Format("-noquery {0}  -dNumCopies={1} -all {4} -printer \"{2}\" \"{3}\"",
                                            isPortrait ? "-portrait" : "-landscape", noOfCopies != 1 ? noOfCopies : 1,
                                            printerName, filename, printInGrey ? "-grey" : "-colour");
            try
            {

                var gsProcessInfo = new ProcessStartInfo
                                        {
                                            WindowStyle = ProcessWindowStyle.Hidden,
                                            FileName = _ghostScriptLocation,
                                            Arguments = processArgs
                                        };
                using (var gsProcess = Process.Start(gsProcessInfo))
                {
                   gsProcess.WaitForExit();

                }
            }
有帮助吗?

解决方案

Just to update, We have gave-up the Ghostscript approach and deiced to use iTextSharp to grab the document instance and print it. Technically, the iTextSharp doesn't manipulate the document but wrap it before printing.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top