在C#WPF中增加页面大小PrintVisual?
我尝试使用PrintDialog.PrintVisual打印,但当页面大小超过要打印的一张时,有人知道如何解决吗?1。正常打印: 与传统的窗口打印相比,WPF打印更容易。您需要显示PrintDialog并调用PrintDialog的PrintVisual方法。此示例已在btnPrint_OnClick事件处理程序中显示在C#WPF中增加页面大小PrintVisual?,c#,wpf,printdialog,C#,Wpf,Printdialog,我尝试使用PrintDialog.PrintVisual打印,但当页面大小超过要打印的一张时,有人知道如何解决吗?1。正常打印: 与传统的窗口打印相比,WPF打印更容易。您需要显示PrintDialog并调用PrintDialog的PrintVisual方法。此示例已在btnPrint_OnClick事件处理程序中显示 PrintDialog printDlg = new System.Windows.Controls.PrintDialog(); if (printDlg.ShowDialo
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
{
printDlg.PrintVisual(this, "First WPF Print");
}
•Add Reference the ReachFramework.dll.
•Add reference of the System.Printing.dll.
•Get the capabilities of the selected printer.
•Calculate the scaling of the printer with w.r.t. to visual to be printed.
•Transform the visual to be printed to the calculated scale.
•Get the printable area of the paper size.
•Update the layout of the visual to the printable area.
•Print the visual.
代码:示例中的这段代码在btnPrintFit\u OnClick处理程序中调用
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");