Wednesday, 25 September 2013

I have WPF window that i want to Print on paper size **4inch by 6inch**

I have WPF window that i want to Print on paper size **4inch by 6inch**

I have WPF window that i want to Print on paper size 4inch by 6inch.
i dont understand where to set this size?? i am using window size to print
but window size its not working. my printer is not fixed paper size.
this is my print code:
private void _print()
{
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
//printDlg.ShowDialog();
//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(this.ActualWidth, this.ActualHeight);
//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, "Print Page");
}

No comments:

Post a Comment