I'm programming a web page for internal use at my company.
It's supposed to dynamically create PDF documents, and send them to the office printer.
The code I'm using is this:
string processFilename = Microsoft.Win32.Registry.LocalMachine
.OpenSubKey("Software")
.OpenSubKey("Microsoft")
.OpenSubKey("Windows")
.OpenSubKey("CurrentVersion")
.OpenSubKey("App Paths")
.OpenSubKey("AcroRd32.exe")
.GetValue(String.Empty).ToString();
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "open";
info.FileName = processFilename;
info.Arguments = String.Format(@"/t ""{0}"" ""{1}""", pdfFilePath, PrinterSettings.InstalledPrinters[0]);
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.WaitForInputIdle();
System.Threading.Thread.Sleep(6000);
if (false == p.CloseMainWindow())
{
p.Kill();
}
It finds wherever adobe acrobat reader is located through the registry, and opens it with the argument of /t
which sends the next argument pdfFilePath
directly to the printer. After 6 seconds it closes adobe acrobat reader.
This runs just fine on my local computer when debugging it in visual studio 2010.
But when I deploy it on the server using IIS 7.5 it doesn't open adobe acrobat reader at all.
I've checked that it has the correct file path for AcroRd32.exe
and the PDF I'm trying to print.
I've also tried a version of this program which opens the actual PDF file with the verb "Print"
, but adobe acrobat reader still won't open.
I think it might be a permissions issue.
Edit: I've tested this code using Foxit Reader instead of Adobe Acrobat Reader.
string processFilename = Microsoft.Win32.Registry.LocalMachine
.OpenSubKey("Software")
.OpenSubKey("Microsoft")
.OpenSubKey("Windows")
.OpenSubKey("CurrentVersion")
.OpenSubKey("App Paths")
.OpenSubKey("foxitreader.exe")
.GetValue(String.Empty).ToString();
The remaining code is unchanged. It opens Foxit Reader and prints on my local debugging environment. But nothing happens when the code is run on the server.