【发布时间】:2015-09-22 13:04:30
【问题描述】:
我们有一个要求:在服务器端会生成某些 PDF。我们需要让客户端在不打开这些文件的情况下打印输出。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PdfPrinter
{
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles(@"d:\files");
foreach (string file in files.Where(
file => file.ToUpper().Contains(".PDF")))
{
Pdf.PrintPDFs(file);
}
}
}//END Class
public class Pdf
{
public static Boolean PrintPDFs(string pdfFileName)
{
try
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
//Define location of adobe reader/command line
//switches to launch adobe in "print" mode
proc.StartInfo.FileName =
@"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = String.Format(@"/p /h {0}", pdfFileName);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}
proc.EnableRaisingEvents = true;
proc.Close();
KillAdobe("AcroRd32");
return true;
}
catch
{
return false;
}
}
//For whatever reason, sometimes adobe likes to be a stage 5 clinger.
//So here we kill it with fire.
private static bool KillAdobe(string name)
{
foreach (Process clsProcess in Process.GetProcesses().Where(
clsProcess => clsProcess.ProcessName.StartsWith(name)))
{
clsProcess.Kill();
return true;
}
return false;
}
}//END Class
}//END Namespace
上述程序在开发者端运行良好,但在客户端却无法运行。我想我无法调用客户的 Adobe Reader。
谁能帮帮我,我如何调用客户端的 AdobeReader 可执行文件。
【问题讨论】:
-
对,所以你是说他们被允许阅读它(在纸上),也不允许阅读它(在屏幕上)。这简直是愚蠢的。
-
@JK,批评别人的要求不好,实际上我们的要求是不要让客户将PDF保存到他的机器上。