0
私は、ユーザの操作なしでpdfファイルをバッチ印刷するためにC#ラッパーを使用しています。私はC#ラッパーによって動的に作成された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();
}
}
私を助けてください。私はプリンタを自動的に選択してユーザの介入を望まないようにします
Welcome to Stackoverflow Dasun .. –