2011-01-25 167 views
4

當我選擇Microsoft XPS文檔寫入打印機,我的輸出是完美的,但是當我選擇我的HP 1020打印機機,打印機輸出空白副本...以下是代碼....WPF打印問題

private void printButton_Click(object sender, RoutedEventArgs e) 
    { 
     PrintInvoice pi = new PrintInvoice(); 
     pi.DataContext = this.DataContext; 
     PrintDialog printDlg = new System.Windows.Controls.PrintDialog(); 
     if (printDlg.ShowDialog() == true) 
     { 
      pi.Margin = new Thickness(30); 

      //now print the visual to printer to fit on the one page. 
      printDlg.PrintVisual(pi, "First Fit to Page WPF Print"); 
     } 
    } 
+0

的伎倆,你試過簡化PrintInvoice,看看他們是被導致與惠普打印機問題的任何元素? – RQDQ 2011-01-25 14:17:00

+0

PrintInvoice是一個頁面,它在Microsoft XPS Document Writer中的輸出是完美的。 – 2011-01-25 14:28:49

回答

7

這可能是由許多不同的事情造成的。有跡象表明,你可以添加,當正確執行,可能cause the flying men to return with goods and knowledge.

首先,你應該擴展到打印頁面幾步(代碼a2zdotnet):

System.Printing.PrintCapabilities capabilities = 
    printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket); 

//get scale of the print wrt to screen of WPF visual 
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth/this.ActualWidth, capabilities.PageImageableArea.ExtentHeight/
       this.ActualHeight); 

//Transform the Visual to scale 
this.LayoutTransform = new ScaleTransform(scale, scale); 

//get the size of the printer page 
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); 

//update the layout of the visual to the printer page size. 
this.Measure(sz); 
this.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); 

    //now print the visual to printer to fit on the one page. 
    printDlg.PrintVisual(this, "Code ganked from http://www.a2zdotnet.com/View.aspx?id=66"); 

貨物邪教代碼是度量和安排步驟。通常,如果您打電話給Measure並通過new Size(Double.MaxValue, Double.MaxValue)這就是您所需要做的。

第二種儀式涉及碰撞分派器。

visual.DataContext = foo; 
Dispatcher.Invoke((Action)()=>{;}); // bamp 
// print here 

試試看看是否有幫助。

0

XAML確實在某些情況下

<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> 
    <... Name="myPrintElement" /> 
</ScrollViewer >