Home > DeveloperSection > Forums > Find A Bug While Printing PDF Files Using Process
CHAITANYA KIRAN KASANI
CHAITANYA KIRAN KASANI

Total Post:1

Points:7
Posted on    December-01-2012 12:10 AM

 C# C# 
Ratings:


 0 Reply(s)
 1078  View(s)
Rate this:
The Below Is My Code Snippet to Print PDFs From Different Folders
Here It Is Printing One Path PDF File and Leaving Another Path PDF File To Print..But While in Debug Mode It Is Printing All The PDF Files Successfully.
pls Some One Help Me...

  private void btnPrint_Click(object sender, EventArgs e)
  {
string path1= method1();//it is string method that returns string
string path2= method2();
string path3= method3();
string path4= method4();
//Here method1(),method2()...method6() are string methods That returns string.Each String Have Different File Path

 string[] files = { path1,path2,path3,path4 }; 
                foreach (string file in files)
                {
                    PrintPDFs(file);
                   
                }
  }

public static Boolean PrintPDFs(string pdfFileName)
        {
            try
            {
                Process proc = new Process();
                proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                proc.StartInfo.Verb = "print";

                //Get application path will get default application for given file type ("pdf")
                //This will allow you to not care if its adobe reader 10 or adobe acrobat.

               
                proc.StartInfo.FileName = "C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32";
                proc.StartInfo.Arguments = String.Format(@"/p /h {0}", pdfFileName);
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow = true;

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

                proc.EnableRaisingEvents = true;

                proc.Close();
                FindAndKillProcess("AcroRd32");
                return true;
            }
            catch
            {
                return false;
            }
        }


        public static bool FindAndKillProcess(string name)
        {
            foreach (Process clsProcess in Process.GetProcesses())
            {
                if (clsProcess.ProcessName.StartsWith(name))
                {
                    clsProcess.Kill();
                    return true;
                }
            }
            return false;
        }




Don't want to miss updates? Please click the below button!

Follow MindStick