Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:
I want to print the whole Window with content and all controls of WPF Screen which also includes the scrollable datagrid. I want that the datagrid should be printed without scroll. I have tried it to do this by using flow document but not succeeded.

Any help is greatly appreciated.
Posted
Updated 18-May-11 0:39am
v2
Comments
GBVSivaRamKumar 6-Jun-13 3:45am    
hi,
I copied the same code but i am facing problem pls help me. when window is very large i am not getting entire window to print some part of the window is cutting down and the window is getting squeezing. please give some idea that even when the window is too large i need to get entire window to print in pages like page1,page2...

1 solution

Hi
I am not sure how you can negate the scroll but if you want to print the form then you can try: -

C#
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
{
      printDlg.PrintVisual(this, "First WPF Print");
}



The above code will print the WPF form but if you want to print the WPF form to fit the page then try the following: -

PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
   {
      //get selected printer capabilities
      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, "First Fit to Page WPF Print");
 
}


--
AJ
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900