从AcroRD32进行打印只能在控制台中进行,而不能在C#中进行

时间:2019-02-06 13:35:11

标签: c# acrobat

我正在尝试在C#应用程序中使用Adobe AcroRD32.exe CLI选项打印PDF。原始命令如下所示:

cmd /c ""C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t /h "C:\thing\to\print.pdf" "Printer Name""

所以,我尝试用C#调用它:

Process process = new Process();
string processFilename = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
ProcessStartInfo info = new ProcessStartInfo
{
    Verb = "print",
    FileName = processFilename,
    Arguments = String.Format("/t /h \"{0}\" \"{1}\"", filePath, printer.Name),
    CreateNoWindow = true,
    WindowStyle = ProcessWindowStyle.Hidden,
    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
};
process.StartInfo = info;

process.Start();

// The reason for the sleep loop is that, without it, the process just never ends if I instead use process.WaitForExit()
int counter = 0;
while (!process.HasExited)
{
    System.Threading.Thread.Sleep(1000);
    counter += 1;
    if (counter == 10) break;
}

if (!process.HasExited)
{
    process.CloseMainWindow();
    process.Kill();
}

process.Close();

我在那里设置超时时间似乎并不重要,它永远不会打印出来。我实际上也可以看到正在创建的过程:

enter image description here

我可以在“命令行”列中获取内容并手动运行它,它将起作用。

此外,如果我使用Foxit Reader语法将其切换出来,则相同的C#代码也可以工作:

“ C:\ Program Files(x86)\ Foxit Software \ Foxit Reader \ FoxitReader.exe” -t“ C:\ thing \ to \ print.pdf”“打印机名称”

我发现,当我从命令行运行AcroRd32时,出现了两个进程:

enter image description here

通过C#运行时,我只能看到第一个屏幕截图中的一个进程。

我尝试将AcroRd32调用放入批处理脚本中,而不是从C#运行批处理脚本,但结果相同。唯一使我想到的是,在我的应用程序中而不是通过CMD运行时,环境是不同的。此应用程序作为以“本地系统”运行的WCF Windows服务运行。

0 个答案:

没有答案