由于您希望在打印文档时在后台打开 Acrobat 阅读器,因此可以使用以下内容:
private static void RunExecutable(string executable, string arguments)
{
ProcessStartInfo starter = new ProcessStartInfo(executable, arguments);
starter.CreateNoWindow = true;
starter.RedirectStandardOutput = true;
starter.UseShellExecute = false;
Process process = new Process();
process.StartInfo = starter;
process.Start();
StringBuilder buffer = new StringBuilder();
using (StreamReader reader = process.StandardOutput)
{
string line = reader.ReadLine();
while (line != null)
{
buffer.Append(line);
buffer.Append(Environment.NewLine);
line = reader.ReadLine();
Thread.Sleep(100);
}
}
if (process.ExitCode != 0)
{
throw new Exception(string.Format(@"""{0}"" exited with ExitCode {1}. Output: {2}",
executable, process.ExitCode, buffer.ToString());
}
}
您可以通过将上述代码合并到您的项目中并按如下方式使用它来打印您的 PDF:
string pathToExecutable = "c:\...\acrord32.exe";
RunExecutable(pathToExecutable, @"/t ""mytest.pdf"" ""My Windows PrinterName""");
此代码取自http://aspalliance.com/514_CodeSnip_Printing_PDF_from_NET.all
如果您不需要在后台打开 Acrobat Reader,只需像打印任何其他文档一样打印 pdf,您可以查看 PrintDocument 类:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.print.aspx