2013-06-21 189 views
0

因此,我有下面的代碼,當對話框打開時,它顯示打印機設置已更改爲雙面打印,但當我單擊確定並打印時,它不會打印雙面,但是當我手動選擇雙它確實打印正確。任何想法可能是這種情況?在此先感謝您的幫助。 ASP.NET WEB應用程序更改打印機設置

  using (PrintDialog pd = new PrintDialog()) 
      { 

       PrinterSettings ps = new PrinterSettings(); 
       ps.Duplex = Duplex.Horizontal; 
       pd.PrinterSettings = ps; 
       // pd.UseEXDialog = true; 



       if (pd.ShowDialog() == DialogResult.OK) 
       { 
        ProcessStartInfo info = new ProcessStartInfo(filePath); 
        info.Verb = "Print"; 
        info.CreateNoWindow = true; 
        info.WindowStyle = ProcessWindowStyle.Hidden; 
        Process.Start(info); 
       } 





      } 
+0

只是爲了確認它是一個Web應用程序。如果這是一個Web應用程序,我不確定您是否可以設置打印機設置。因爲你的代碼在服務器上運行,但客戶端系統在其他地方。因此覆蓋客戶端偏好可能是不可能的。但我不確定這一點。可能有某種方法。 – Narendra

回答

0

您可以檢查PrinterSettings.CanDuplex屬性。只需設置

PrinterSettings settings = new PrinterSettings(); 

並檢查您的打印機是否支持它。

  • 此屬性獲取一個值,指示打印機是否支持雙面打印。
  • 如果打印機支持雙面打印,則返回true;否則,false

你可以簡單地做這樣的:

 PrintDialog pd = new PrintDialog(); 
     PrintDocument MyPrintDocument = new PrintDocument(); 
     MyPrintDocument.PrintPage += new PrintPageEventHandler(PrintPageEvent); 
     pd.PrinterSettings.PrintRange = PrintRange.AllPages; 
     MyPrintDocument.PrinterSettings.PrintRange = PrintRange.AllPages; 
     MyPrintDocument.Print(); 

其中PrintPageEvent是觸發Print()的事件;

+0

PrinterSettings.canDuplex是隻讀的,我相信 – dansasu11

+0

@paabobo哦,是啊.. –