简体   繁体   中英

Process.Startinfo to print PDF not working in Windows Server 2003 from ASP.NET

I have the below code in ASP.NET C# and it work fine in local system + production machine when i tested in debug mode. but it doesn't work when i uploading to IIS.

ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = Server.MapPath(filePath);
                startInfo.Verb = "print";
                startInfo.Arguments = "Printer Name";
                Process proc = new Process();
                proc.StartInfo = startInfo;
                proc.Start();

                proc.WaitForExit(5000);
                if (proc.HasExited == false)
                {
                    proc.Kill();
                }

Things i tried.

  1. Control panel > Admin Services > Services > IIS Admin Service > Log on Tab > check to interact with desktop. Reset IIS Admin and IIS.
  2. Printer Properties > Security > Grand ASPNET, NETWORK SERVICE, EVERYONE to full access.
  3. Tried to set another printer as Default Printer. Reinstall / Add Printer.

I tried all the above with no success. finally i tried below in my machine.config.

  1. WINNT>Microsoft.NET>Framework>v2.52something>Config> machine.config

I replaced this

processModel autoConfig="true"

with this

processModel userName="SYSTEM" password="AutoGenerate"

and i am getting this message

"Before you can perform print-related tasks you need to install a printer"

i am using acrobat 7 and i can print the test page from printer itself and from acrobat software.

The issue may be that IIS runs under a different user that has less permissions than a typical User. See System.Diagnostics.Process.Start not work from an IIS

I fixed it on my server by changing the ProcessModel Identity to a user that has permissions. Probably a workaround and bad practice, but it worked. {Application Pool} -> Advanced Settings -> Identity -> Custom Account (Also toggle Load User Profile to true)

you can use Verb if acrobat is installed on you machine. and pass printer name as arguments

var fileName = @"c:\pdf\file.pdf";
            var startInfo = new ProcessStartInfo(fileName);
            string verbToUse = "PrintTo";
            startInfo.Verb = verbToUse;
            startInfo.Arguments = "PrinterName";
            Process p = Process.Start(startInfo);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM