none
Close AdobeReader after printing file RRS feed

  • Question

  • Hello

    Any ideas how to close Adobe window after this command.
    Or how to kill this process?

    Or may be there is the way to skip opening window?
    Thanks in advance

    My code:

    public static bool Print(string pdfFileName, string PrinterName)
            {
                try
                {
                    Process.Start(
                       Registry.LocalMachine.OpenSubKey(
                            @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                            @"\App Paths\AcroRd32.exe").GetValue("").ToString(),
                       string.Format("/h /t \"{0}\" \"{1}\"", pdfFileName, PrinterName));
                    return true;
                }
                catch { }
                return false;

            }


    Tuesday, July 23, 2019 8:11 AM

All replies

  • You shouldn't need to do any of that unless you explicitly need to open Acrobat. Furthermore your registry checking is completely dependent upon how the program is getting installed and therefore is not necessarily reliable.

    When opening a PDF you should use whatever reader the user has configured, whether it is Adobe or not. To do that use Process.Start.

    var info = new ProcessStartInfo() {
       Verb = "Print",
       WindowStyle = ProcessWindowStyle.Hidden,
       CreateNoWindow = true,
       FileName = pdfFileName
    };
    
    Process.Start(info);
    

    The related app should print the PDF and terminate. If for some reason it doesn't and you know the printing is done then call `Kill` on the returned `Process` object.

    Also, if you need to print to a specific printer then somebody recommended using PrintTo instead.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, July 23, 2019 1:52 PM
    Moderator
  • Hi Close AdobeReader after printing file, 

    Thank you for posting here.

    According to your problem, I make a test which will kill process in five seconds.

    Here’s the code and you can refer it:

            public static void pdfTest(string pdfFileName, string PrinterName)
            {
                string processFilename = Registry.LocalMachine
                     .OpenSubKey("SOFTWARE")
                     .OpenSubKey("Microsoft")
                     .OpenSubKey("Windows")
                     .OpenSubKey("CurrentVersion")
                     .OpenSubKey("App Paths")
                     .OpenSubKey("AcroRd32.exe")
                     .GetValue(String.Empty).ToString();
    
                ProcessStartInfo info = new ProcessStartInfo()
                {
                    FileName = processFilename,
                    Verb = "print",
                    Arguments = string.Format("/h /t \"{0}\" \"{1}\"", pdfFileName, PrinterName),
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    UseShellExecute = false
                };
    
                Process p = Process.Start(info);
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    
                if (!p.WaitForExit(5000)) 
                {
                    p.CloseMainWindow();
                    p.Kill();
                }
            }

    Hope it can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 24, 2019 5:43 AM
    Moderator