Printing pdf's without opening the print dialogbox

坚强是说给别人听的谎言 提交于 2019-12-25 01:08:29

问题


I have created a function for printing pdf's through adobe reader. It all works fine but I am unable to suppress the print dialog box. What I want is to print the file directly through the printer without the print dialog box popping up.

This is the function for printing but the print dialog pops up everytime it is called. I am doing a batch pdf printing so I don't want it pop every time.

public static bool PrintPDFs(string pdfFileName)
    {
        try
        {
            var proc = new Process
                           {
                               StartInfo =
                                   {
                                       WindowStyle = ProcessWindowStyle.Hidden,
                                       Verb = "print",
                                       FileName =
                                           Registry.LocalMachine.OpenSubKey("Software")
                                                   .OpenSubKey("Microsoft")
                                                   .OpenSubKey("Windows")
                                                   .OpenSubKey("CurrentVersion")
                                                   .OpenSubKey("App Paths")
                                                   .OpenSubKey("AcroRd32.exe")
                                                   .GetValue(string.Empty)
                                                   .ToString(),
                                       //Define location of adobe reader/command line
                                       //switches to launch adobe in "print" mode
                                       Arguments = string.Format(@"/p /h {0}", pdfFileName),
                                       UseShellExecute = false,
                                       CreateNoWindow = true
                                   }
                           };

            proc.Start();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            if (!proc.HasExited)
            {
                proc.WaitForExit(10000);
            }

            proc.EnableRaisingEvents = true;
            proc.Close();
            KillAdobe("AcroRd32");
            return true;
        }
        catch
        {
            return false;
        }
    }

来源:https://stackoverflow.com/questions/18678114/printing-pdfs-without-opening-the-print-dialogbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!