我需要使用ProcessStartInfo
打印pdf文件。
string docInvoicePath = @"[Path]";
string printername = "\"PRN-OFFICE\"";
string driver = "\"Xerox Global Print Driver PS\"";
string port = "\"[IP]\"";
ProcessStartInfo psInfo = new ProcessStartInfo
{
FileName = @"""C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32""",
Arguments = String.Format("/s /o /h /t " + docInvoicePath + " " + printername + " " + driver + " " + port),
Verb = "print",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = false
};
Process process = Process.Start(psInfo);
process.WaitForExit(6000);
if (process.HasExited == false)
{
process.Kill();
}
process.Close();
filename
和arguments
在粘贴到cmd
时工作正确。
代码工作正常,但在Process.Start
之后,WaitForExit
程序无法完成。我收到超时错误:
System.Threading.ThreadAbortException:线程正在中止。 在System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle,UInt32 millisecondsTimeout,Boolean hasThreadAffinity,Boolean exitContext) 在System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle,Int64 millisecondsTimeout,Boolean hasThreadAffinity,Boolean exitContext) 在System.Diagnostics.Process.WaitForExit(Int32毫秒)......
我搜索并尝试了一些事情,例如设置<httpRuntime executionTimeout="300"/>
并遇到 500 或类似于process.WaitForExit(6000);
以及更高的代码,其中没有任何例外但没有打印
是否有错误或我遗失了什么?
修改 我上面改了我的代码块。现在代码在调试模式下工作,但它仍然不会在发布时打印我的文档。我也尝试使用不同的用户。 在调试模式下,代码打印文档,但在 kill 查询中运行。
ProcessStartInfo.Verbs
会返回参数异常,但我不知道原因。
答案 0 :(得分:0)
经过大量的尝试,测试和搜索后,我确信我的代码可以运行。 所以我仍然不知道为什么我的代码停止工作。 但是从服务器上的Adobe Reader 9.0更改为7.0现在可以正常工作。
当我在本地使用Adobe Reader 9.0进行调试时,它也有效,所以我想也许网络服务器上有更新。我还没有确认过。