从C#启动Acrobat Reader 10.0:如何最小化

本文关键字:最小化 启动 Acrobat Reader | 更新日期: 2023-09-27 18:27:19

我正在启动Reader10.0,以便从Win7系统上的C#程序向打印机发送PDF文件。以下是我现在正在做的事情:

startInfo.FileName = adobeReaderPath;
string args = String.Format("/t '"{0}'" '"{1}'"", this.pdfFileName, this.printerName);
startInfo.Arguments = args;
startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process process = Process.Start(startInfo);

我注意到,像这样(或从命令提示符)启动Reader实际上启动了2个AcroRd32.exe可执行文件。两者都没有最小化。我还尝试了ProcessWindowStyle.Hiddden,得到了同样的结果。

有没有一种方法可以迫使阅读器开始最小化?

谢谢!

从C#启动Acrobat Reader 10.0:如何最小化

启动进程后,您可以获得它的MainWindowHandle,并使用p/Invoke将其最小化:

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
//..
ShowWindow(process.MainWindowHandle, 11);  //11 is ForceMinimized

在命令行中尝试包含/h。这将启动一个最小化到任务栏的Adobe Reader实例。然而,没有"好"的选择来完全隐藏它(据我所知)。除了用Win32 API破解一些不可预测的东西。启动一些应用程序最小化的更通用的方法是通过API。请参阅Steve的帖子。

这应该做到:

string args = String.Format("/h /t '"{0}'" '"{1}'"", this.pdfFileName, this.printerName);

使用您提到的代码,您实际上无法使用Adobe acrobat阅读器将pdf文档直接发送到打印机。

你需要的是一个.net pdf api,它具有打印pdf的功能。您可以添加对项目的引用,然后开始使用api。你可以在互联网上搜索/搜索souchapi,这些api也是免费的,易于使用。

请参阅:http://www.robvanderwoude.com/commandlineswitches.php#Acrobat

打开PDF文件:

AcroRd32.exe PdfFile

在Adobe Reader的新实例中打开PDF文件:

AcroRd32.exe /N PdfFile

在第7页打开PDF文件:

AcroRd32.exe /A "page=7=OpenActions" PdfFile

打开导航窗格处于活动状态的PDF文件,缩小到50%,然后搜索并突出显示单词"批次":

AcroRd32.exe /A "zoom=50&navpanes=1=OpenActions&search=batch" PdfFile

使用对话框打印PDF文件:

AcroRd32.exe /P PdfFile

以静默方式打印PDF文件

AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ] ]

最后一个命令将打开一个新的Adobe Reader窗口,打印PDF文件,然后终止其窗口,除非该窗口恰好剩下的唯一Adobe Reader窗口:至少有一个Adobe Reader窗口将保持打开状态。

编辑:http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf#page=5

Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
proc.StartInfo.FileName = @"Path of Adobe exe";
proc.StartInfo.Arguments = String.Format(@"/p /h {0}", fileToPrint);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();