2011-12-30 71 views
1

は、私は私のflowdocumentを印刷する方法である:WPFでプリンタステータスを取得する方法は?ここ

PrintDialog pd = new PrintDialog(); 
LocalPrintServer local = new LocalPrintServer(); 
PrintQueue pq = local.DefaultPrintQueue;//GetPrintQueue("[Printer Name]"); //e.g. local.GetPrintQueue("Microsoft XPS Document Writer"); 
pd.PrintQueue = pq; 
PrintTicket pt = pq.DefaultPrintTicket; 
pt.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA5);// or we can specify the custom size(width, height) here 
pd.PrintTicket = pt; 
pt.PageBorderless = PageBorderless.Borderless; 
pt.PageOrientation = PageOrientation.ReversePortrait; 
PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket); 
double sizeWidth = capabilities.PageImageableArea.ExtentWidth; 
double sizeHeight = capabilities.PageImageableArea.ExtentHeight; 
var fd = new FlowDocument(); 

DocumentPaginator sd = ((IDocumentPaginatorSource)fd).DocumentPaginator; 
sd.PageSize = new Size(sizeWidth + 20, sizeHeight); 
pd.PrintDocument(sd, "My Doc"); 
// GET THE PRINTER STATUS IN MESSAGE BOX HERE.. 
MessageBox.Show(printerStatus()); // printerStatus() is a pseudo method to retrieve the status of the printer. 

がどのように私は、プリンタの現在の状態を取得できるようになり、出力、印刷、紙、紙詰まり、プリンタオフラインなどのメッセージのうち??? ?検索の際

は、私はこのページに出くわした:http://msdn.microsoft.com/en-us/library/system.printing.printqueuestatus.aspx

私はそれの使用に関する見当もつかないが。あなたはどんな体でも私にそれを手伝ってもらえますか?

この印刷プロセスは、STAスレッドで実行されています。

+0

私がLPTプリンタのポートの状態を確認することができため、このリンクを経由してプリンタから聴きたいです。 – user995387

答えて

2

あなたはこの

using System.Management; 

class PrinterOffline 
{ 
    private static void Main(string[] args) 
    { 
      // Set management scope 
      ManagementScope scope = new ManagementScope("\\root\\cimv2"); 
      scope.Connect(); 

     // Select Printers from WMI Object Collections 
     ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer"); 
     string printerName = ""; 
     foreach (ManagementObject printer in searcher.Get()) 
     { 
      printerName = printer("Name").ToString().ToLower(); 
      if (printerName.Equals("Name_Of_Printer")) 
      { 
       Console.WriteLine("Printer = " + printer("Name")); 
       if (printer("WorkOffline").ToString().ToLower().Equals("true")) 
       { 
         // printer is offline by user 
         Console.WriteLine("Your Plug-N-Play printer is not connected."); 
       } 
       else 
       { 
        // printer is not offline 
         Console.WriteLine("Your Plug-N-Play printer is connected."); 
       } 
      } 
     } 
    } 
} 

PLSのように確認することができますが、しかし私は、USBプリンタを使用しています、より多くのinformation on status of the printer

関連する問題