0
我正在使用c#封装来批量打印PDF文件,而无需用户交互。我正在使用一个由c#wrapper动态创建的ps文件,并提供该ps文件作为进程启动参数。使用ps文件的原因是gs不支持动态用户友好假脱机程序名称作为命令行参数。他的问题是,当我使用ps文件时,gs不会自动选择打印机。它总是要求手动选择打印机。这里是代码ghostscript命令行参数ps文件中的打印机选择
class Program
{
static void Main(string[] args)
{
try
{
string path = Application.StartupPath + "\\wd.print";
StreamReader sr = new StreamReader(path);
string[] content = sr.ReadToEnd().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
sr.Close();
string printer = content[0];
for (int i = 1; i < content.Length; ++i)
{
ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.Arguments = String.Format(" setup.ps -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sOutputFile=\"\\\\spool\\{0}\" \"{1}\"",
printer,
content[i]);
String spoolerName = content[i].Substring(content[i].IndexOf("$")+1);
//creates the dynamic ps file named setup.ps
generateSettings(spoolerName);
string gs = Application.StartupPath + @"\gs\gswin32c.exe"; ;
psInfo.FileName = gs;
psInfo.UseShellExecute = false;
Process process = Process.Start(psInfo);
process.WaitForExit();
Console.ReadLine();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Console.Write(ex.Message);
Console.ReadLine();
}
}
protected static void generateSettings(String name)
{
//the code which creates the dynamic ps file named setup.ps
FileStream file=File.Create("setup.ps");
StreamWriter writer = new StreamWriter(file);
writer.WriteLine("mark");
writer.WriteLine(" /NoCancel true ");
writer.WriteLine(" /UserSettings");
writer.WriteLine(" <<");
writer.WriteLine(" /DocumentName (" + name + ")");//custom name for windows print spooler
writer.WriteLine(" >>");
writer.WriteLine(" (mswinpr2) finddevice");
writer.WriteLine(" putdeviceprops");
writer.WriteLine("setdevice");
writer.Flush();
writer.Close();
file.Close();
}
}
请帮助我。我想自动选择打印机,因此它不需要用户干预
欢迎来到Stackoverflow Dasun .. – 2013-05-20 11:11:02