1
votes

I have a web application on IIS and I’ll print a file pdf.

  • Printers are shared printers, physically connected to another computer.
  • The website have an Application Pool Identity and the virtual account (DomainName\NameComputer$) have full permissions on printers.
  • ‘IIS APPPOOL\NameAP’ have full control on Acrobat Reader (AcroRd32.exe)
  • Operation Systems: Windows Server 2008 R2

I use Process class with this code:

ProcessStartInfo infoPrintPdf = new ProcessStartInfo();
infoPrintPdf.FileName = pathPdf;
string printerName = "\\namePC\namePrinter";
infoPrintPdf.FileName = "...\AcroRd32.exe";
infoPrintPdf.Arguments = string.Format("/t {0} \"{1}\"", 
    pathPdf, printerName);
infoPrintPdf.CreateNoWindow = true;
infoPrintPdf.UseShellExecute = false;
infoPrintPdf.WindowStyle = ProcessWindowStyle.Hidden;
Process printPdf = new Process();
printPdf.StartInfo = infoPrintPdf;
printPdf.Start();
printPdf.WaitForExit();
printPdf.Close();

Process AcroRd32.exe remains in running state and don’t print. Any idea?


I try to open file pdf on server and doesn't work. An extract: Process.Start(@"...\Print.pdf"); The process AcroRd32.exe is in running with username ‘IIS APPPOOL\NameAP’ With Visual Studio in debug this code works.

2

2 Answers

0
votes

I've tested in Console app and it's working, modify yr code and use better naming:

var exePath = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
var pdfFile = @"E:\program.pdf";
var infoPrintPdf = new ProcessStartInfo
{
    FileName = exePath,
    Arguments = String.Format("/t {0} ", pdfFile),
    CreateNoWindow = true,
    UseShellExecute = false,
    WindowStyle = ProcessWindowStyle.Hidden
};

var printPdf = new Process();
printPdf.StartInfo = infoPrintPdf;
printPdf.Start();
printPdf.WaitForExit();
printPdf.Close();

Other than app pool Identity, check the argument u r passing.

0
votes

I tested it just now, and it printed for me.

The problem is likely your printer name: "....\file.pdf". That should be the name of a printer as it appears in 'Devices and Printers' in the Windows Control Panel. If you do not provide a printer name, it uses the default printer.

After fixing that, if it still doesn't print, maybe the app pool identity doesn't have access to your printer? There is a Security tab when you open the printer properties. Mine shows that 'Everyone' is there by default, so this may not be the issue, but you can try adding the app pool group (IIS_IUSRS) and see if it makes a difference.

In my test, Reader did stay open after printing. Apparently that behavior can't be changed. From the Adobe forums:

It's not possible to do that with Reader.

You can use a separate command to kill the Reader process, but the problem is you can't tell it to wait until the print command has been sent, so it's not likely to work.

But I did find this program that was built just to get around this issue: http://www.biopdf.com/acrowrap/close_adobe_reader.php