We have an requirement: There are certain PDF's which will be generated at Server Side. We need to make Client to take PrintOut of these files without opening them.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PdfPrinter
{
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles(@"d:\files");
foreach (string file in files.Where(
file => file.ToUpper().Contains(".PDF")))
{
Pdf.PrintPDFs(file);
}
}
}//END Class
public class Pdf
{
public static Boolean PrintPDFs(string pdfFileName)
{
try
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
//Define location of adobe reader/command line
//switches to launch adobe in "print" mode
proc.StartInfo.FileName =
@"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
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();
KillAdobe("AcroRd32");
return true;
}
catch
{
return false;
}
}
//For whatever reason, sometimes adobe likes to be a stage 5 clinger.
//So here we kill it with fire.
private static bool KillAdobe(string name)
{
foreach (Process clsProcess in Process.GetProcesses().Where(
clsProcess => clsProcess.ProcessName.StartsWith(name)))
{
clsProcess.Kill();
return true;
}
return false;
}
}//END Class
}//END Namespace
The above program is working fine from Developer Side, but Its not working on Client Side. I think I am unable to invoke Client's Adobe Reader.
Can anyone help me, how can I invoke client's AdobeReader executable file.