Aufgabenstellung war das Drucken von PDF Dokumenten die automatisiert auf einem Netzlaufwerk abgelegt werden. Letztendlich habe ich es über ein kleines C# Programm gelöst welches den Acrobat aufruft, das Dokument druckt und anschließend löscht.
Im Beispiel werden alle Dokumente gedruckt, die im Ordner „U:\PRINT\“ abgelegt werden. Dem Programm können zwei Parameter übergeben werden, einmal der Pfad zum Acrobat Reader und einmal der Ordner der überwacht werden soll.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String strAcrobat = @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
String strPath = @"C:\Users\Daniel\Desktop\PRINT\";
if (args.Length == 2 && !String.IsNullOrEmpty(args[0])) strAcrobat = args[0];
if (args.Length == 2 && !String.IsNullOrEmpty(args[1])) strPath = args[1];
do
{
while (!Console.KeyAvailable)
{
string[] arFiles = Directory.GetFiles(strPath);
foreach (String strFile in arFiles)
{
Console.WriteLine("Drucke :" + strFile);
ProcessStartInfo procStartInfo = new ProcessStartInfo(strAcrobat, " /p /h " + strFile);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}
proc.EnableRaisingEvents = true;
proc.Close();
KillAdobe("AcroRd32");
Console.WriteLine("Lösche :" + strFile);
Console.WriteLine("");
File.Delete(strFile);
}
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
} // static void Main(string[] args)
private static bool KillAdobe(string name)
{
foreach (Process clsProcess in Process.GetProcesses().Where(clsProcess => clsProcess.ProcessName.StartsWith(name)))
{
clsProcess.Kill();
return true;
}
return false;
} // private static bool KillAdobe(string name)
}
}