Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks all for your comments. Unfortunately this "php start printjob" thing was part of a larger project that was cancelled today because of, well... I dont know... political reasons. Guess the project is pretty much dead.</p> <p>Anyway, I tried myself a few more times in the last days and could not get it to work with IIS. My solution that I implemented and tested already: remove IIS, install a XAMPP or WAMPP package with a local apache and PHP that runs with <em>admin access rights</em>. </p> <p>This did the trick. I used <code>pclose(popen('...command...', 'r'));</code> in PHP in order to start the <code>.exe</code> and so that PHP does not wait until the PDF is finished. It all worked great. </p> <p>Here is my C# code which starts the print job using Acrobat Reader</p> <pre><code>public void Print(string pathname, string acrobatDirectory) { var proc = new Process { StartInfo = { Arguments = String.Format("/t \"{0}\"", pathname), FileName = acrobatDirectory, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, RedirectStandardError = false, } }; proc.Start(); } </code></pre> <p>The first argument is the path to the PDF that should be printed, the second parameter is the absolute path to the <code>AcroRd32.exe</code>.</p> <p>The only problem left was that <code>AcroRd32.exe</code> was started, printed and never got closed again. So every printjob started a new instance of <code>AcroRd32.exe</code> (I am using Acrobat Reader 9.0). So if you printed 10 times, 10 acrobat reader instances were created.</p> <p>What I did was starting the print job, then waiting X seconds, hoping that the printer was finished and then killing all <code>AcroRd32.exe</code> instances:</p> <pre><code>public void Print(string pathname, string acrobatDirectory) { Debug.WriteLine("Printing..."); Printer.Print(pathname, acrobatDirectory); Thread.Sleep(30000); try { Debug.WriteLine("Trying to kill runnung AcroRd32.exe's "); FindAndKillProcess("AcroRd32"); } catch (Exception) { Debug.WriteLine("AcroRd32.exe could not be killed..."); } } private bool FindAndKillProcess(string name) { foreach (Process clsProcess in Process.GetProcesses()) { if (clsProcess.ProcessName.StartsWith(name)) { clsProcess.Kill(); return true; } } return false; } </code></pre> <p>This worked out quite well.</p> <hr /> <p>Note that the above (killing all <code>AcroRd32.exe</code> and running PHP with admin privilegs) was only doable because: <strong>The whole thing is only used by one user at a time and has a very limited area of use</strong>.</p> <p>It should be used on a touchscreen application deployed at the clients POS. A salesman would use the PHP app in order to configure a product, and then PHP would call my .exe which would create and print a PDF in the background. The printed document is then handed to the client. <strong>So security etc. was not really a concern in this case.</strong></p> <hr /> <p><strong>If anyone has a solution in order to use it with IIS, I am still willing to accept it as an answer.</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload