简体   繁体   English

使用ASP.NET和Acrobat Reader打印PDF

[英]Print PDF with ASP.NET and Acrobat Reader

I have a web application on IIS and I'll print a file pdf. 我在IIS上有一个Web应用程序,我将打印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. 该网站具有应用程序池标识,并且虚拟帐户(DomainName \\ NameComputer $)对打印机具有完全权限。
  • 'IIS APPPOOL\\NameAP' have full control on Acrobat Reader (AcroRd32.exe) IIS APPPOOL \\ NameAP对Acrobat Reader(AcroRd32.exe)具有完全控制权
  • Operation Systems: Windows Server 2008 R2 操作系统:Windows Server 2008 R2

I use Process class with this code: 我使用带有以下代码的Process类:

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. 进程AcroRd32.exe保持运行状态,并且不打印。 Any idea? 任何想法?


I try to open file pdf on server and doesn't work. 我尝试在服务器上打开文件pdf,但不起作用。 An extract: Process.Start(@"...\\Print.pdf"); 摘录:Process.Start(@“ ... \\ Print.pdf”); The process AcroRd32.exe is in running with username 'IIS APPPOOL\\NameAP' With Visual Studio in debug this code works. 进程AcroRd32.exe正在使用用户名“ IIS APPPOOL \\ NameAP”运行,而在Visual Studio中调试此代码即可。

I tested it just now, and it printed for me. 我刚刚进行了测试,并为我打印了。

The problem is likely your printer name: "....\\file.pdf" . 问题可能出在您的打印机名称上: "....\\file.pdf" That should be the name of a printer as it appears in 'Devices and Printers' in the Windows Control Panel. 这应该是Windows控制面板中“设备和打印机”中显示的打印机名称。 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. Mine显示默认情况下“每个人”都在那儿,所以这可能不是问题,但是您可以尝试添加应用程序池组(IIS_IUSRS),看看是否有所作为。

In my test, Reader did stay open after printing. 在我的测试中,Reader在打印后确实保持打开状态。 Apparently that behavior can't be changed. 显然,行为无法更改。 From the Adobe forums : Adobe论坛

It's not possible to do that with Reader. 使用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. 您可以使用一个单独的命令来终止Reader进程,但是问题是您不能告诉它等到发送print命令后再使用,因此它不太可能起作用。

But I did find this program that was built just to get around this issue: http://www.biopdf.com/acrowrap/close_adobe_reader.php 但是我确实找到了专门为解决此问题而构建的程序: http : //www.biopdf.com/acrowrap/close_adobe_reader.php

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 ur passing. 除了应用程序池标识外,请检查传递的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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