2012-03-02 3 views
0

사용자 상호 작용없이 pdf 파일을 일괄 인쇄하기 위해 C# 래퍼를 사용하고 있습니다. 나는 C# 래퍼에 의해 동적으로 생성되는 ps 파일을 사용 중이며 ps 파일을 프로세스 시작 args로 제공합니다. ps 파일을 사용하는 이유는 gs가 명령 줄 args와 같이 동적 인 사용자 친화적 인 스풀러 이름을 지원하지 않기 때문입니다. 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(); 




    } 
} 

도와주세요. 프린터를 자동으로 선택하여 사용자 개입을 원하지 않으므로

답변

0

.PS 파일을 만든 다음이 메커니즘을 통해 선택한 프린터로 데이터를 보내십시오. How to send raw data to a printer. 프린터 목록을 가져 와서 프로그래밍 방식으로 선택한 다음 .PS를 장치로 보낼 수 있습니다. 파일을 보낼 때 스풀러/작업 이름에 나타나는 것을 지정할 수 있습니다.

+0

Welcome to Stackoverflow Dasun .. –