多个文档发送到默认打印机队列顺序

时间:2016-10-23 18:30:58

标签: c# printing printqueue

我正在开发一个无需用户交互就可以作为打印代理工作的应用程序。在那里,我必须考虑以下条件。

  • 下载文件不应该是用户访问。
  • 文件打印后可以删除。
  • 下载文档可以是Image / PDF或word.docx
  • 应首先打印首先下载的文件。

到目前为止,我能够完成如下操作。   - 创建观察者方法以赶上新的下载文件。

public void catchDocuments()
        {
            if (!string.IsNullOrEmpty(Program.docDirectory))
            {
                file_watcher = new FileSystemWatcher();
                file_watcher.Path = Program.docDirectory;
                file_watcher.EnableRaisingEvents = true;
                file_watcher.Created += new FileSystemEventHandler(OnChanged);
            }            
        }

当新文件出现时,它将触发Onchange事件并打印文档。

string extension = Path.GetExtension(args.FullPath);
if (extension.Equals(@".png") || extension.Equals(@".jpeg") || extension.Equals(@".jpg"))
{
    docCtrl.imageToByteArray(nFile);
    docCtrl.printImage();
}
else if (extension.Equals(@".pdf"))
{                     
    docCtrl.PrintPDF(nFile);
}

但我的问题是,在下载文件的完整打印过程之前下载另一个文件时,应用程序将无法正常工作。

我使用了打印选项,如下所示。

//For Image printing
public void printImage()
{     
    System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
     pd.PrintPage += new PrintPageEventHandler(PrintPage);        
    PrintDialog pdi = new PrintDialog();
    pdi.Document = pd;
    pdi.PrinterSettings.PrinterName;
    pd.Print();    
}

    //For PDF Printing
public void PrintPDF(string path)
    {
       PrintDialog pdf = new PrintDialog();
       Process p = new Process();
       pdf.AllowSelection = true;
       pdf.AllowSomePages = true;
       p.EnableRaisingEvents = true; //Important line of code
       p.StartInfo = new ProcessStartInfo()
         {
           CreateNoWindow = true,
           Verb = "print",
           FileName = path,
         };
       p.Start();
       p.WaitForExit();
       p.Close();
    }

我怎么能克服这个问题。我会非常感谢你的好主意。

0 个答案:

没有答案