Printing ps文件中的ghostscript命令行参数打印机选择

Printing ps文件中的ghostscript命令行参数打印机选择,printing,ghostscript,Printing,Ghostscript,我使用c#包装器批量打印pdf文件,无需用户交互。我使用的是一个ps文件,它是由c#wrapper动态创建的,我将该ps文件作为进程开始参数提供。使用ps文件的原因是gs不支持将动态用户友好型后台处理程序名称作为命令行参数。问题是当我使用ps文件时,gs不会自动选择打印机。它总是要求手动选择打印机。这是密码 class Program { static void Main(string[] args) { try { s

我使用c#包装器批量打印pdf文件,无需用户交互。我使用的是一个ps文件,它是由c#wrapper动态创建的,我将该ps文件作为进程开始参数提供。使用ps文件的原因是gs不支持将动态用户友好型后台处理程序名称作为命令行参数。问题是当我使用ps文件时,gs不会自动选择打印机。它总是要求手动选择打印机。这是密码

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();




    }
}
类程序
{
静态void Main(字符串[]参数)
{
尝试
{
字符串路径=Application.StartupPath+“\\wd.print”;
StreamReader sr=新的StreamReader(路径);
string[]content=sr.ReadToEnd().Split(新字符[]{'\n','\r'},StringSplitOptions.RemoveEmptyEntries);
高级关闭();
字符串打印机=内容[0];
for(int i=1;i

请帮帮我。我想自动选择打印机,这样它就不需要用户干预

为什么不创建.PS文件,然后通过以下机制将数据发送到您选择的打印机:。您可以获取打印机列表,通过编程选择打印机,然后将.PS发送到设备。发送文件时,可以指定后台打印程序/作业名称中显示的内容