4 Replies Latest reply on May 13, 2008 12:35 PM by (chicks)

    Problems Background Printing PDF from C# Application

      Hello,

      We are having a lot of problems trying to print a PDF file in the background using a C# application that is executed via SQL Server Agent. The output should be printed to a local printer (HP Color LaserJet 1600) connected via a USB port.

      We have a C# application that calls System.Diagnostics.Process to run Acrobat Reader (weve tried both v8.0.0 and v8.1.2), open an existing PDF file, and send it to the local printer. The code is shown below.

      System.Diagnostics.Process process = new System.Diagnostics.Process();
      process.Refresh();
      process.StartInfo.Arguments = "/t C:\Temp\TestPDF.pdf"; // and tried "/t C:\Temp\TestPDF.pdf PrinterName"
      process.StartInfo.CreateNoWindow = false;
      //process.StartInfo.Domain;
      //process.StartInfo.ErrorDialog = false;
      process.StartInfo.FileName = "C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRd32.exe";
      //process.StartInfo.Password;
      //process.StartInfo.UserName;
      process.StartInfo.UseShellExecute = false;
      //process.StartInfo.Verb = "Print";
      process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
      process.StartInfo.WorkingDirectory = new System.IO.FileInfo(m_PDFPathFile).DirectoryName;
      process.Start();

      Weve tried just about every combination of the process objects properties trying to get the PDF file to print. But, it never works. The code executes without error, just nothing ever shows up on the printer.

      More info Were executing our custom C# application via a SQL Server Agent job. SQL Server Agent is running as Local System account. The Job Step Type is Operating System (CmdExec), with Run as set to SQL Server Agent Account. The command is simply the path and file name of our custom C# application (e.g., C:\Temp\PrintPDF.exe).

      Again, we get no errors/exception and no job failures, but the PDF never gets printed.

      How can we re-code or fix our situation?
      What can be done/tried?

      All help is appreciated. We are stuck.
      Thanks.
        • 1. Re: Problems Background Printing PDF from C# Application
          (Aandi_Inston) Level 1
          The command line arguments are unsupported but they ARE documented in
          the Acrobat Developer FAQ: you don't match that specification. But you
          can also expect problems trying to use Adobe Reader from an impersonal
          server process.

          Aandi Inston
          • 2. Re: Problems Background Printing PDF from C# Application
            I think you're having problems with the Arguments property => no quotation marks around the expected arguments. here is a piece of code that works on my pc:

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.Refresh();
            process.StartInfo.Arguments = @"/t ""c:\test.pdf""";
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.FileName = @"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            process.Start();

            hope this helps!
            Henk
            • 3. Re: Problems Background Printing PDF from C# Application
              I am having a similar issue in VB2005. It appears that you can only print if the "useshellexecute" is set to true. The only caveat to this is when "useshellexecute" is set to true, you cannot start the process under a different username. Does anyone know a way around this issue?

              Thanks,

              Jeff
              • 4. Re: Problems Background Printing PDF from C# Application
                Level 1
                > Server Agent is running as Local System account.

                You'll need to login as Local System, and make sure it has the print driver installed. Most likely it has no printers that it can access.

                Reader displays errors in dialogs, so it's likely that you have lots of invisible dialogs with errors on them.

                To login as System, use the "at" command:

                c:\> at 13:30 /interactive "cmd.exe"

                Just use a time a minute or two in the future. When the new command prompt opens, type this in it:

                c:\WINNT\System32> start acrord32

                Now, you are running Reader as the System user. Load a PDF, and try to print. You will most likely get an error dialog.