【发布时间】:2013-09-26 04:56:59
【问题描述】:
我有 WPF 窗口,我想在 4 英寸 x 6 英寸的纸张上打印。
我不明白在哪里设置这个尺寸??
我正在使用窗口大小进行打印,但窗口大小不起作用。
我的打印机不是固定的纸张尺寸。
这是我的打印代码:
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");
}
【问题讨论】:
-
尝试设置
printDlg.PrintTicket.PageMediaSize -
@nit :但是如何以英寸为单位设置页面?我有窗口大小 Height="490" Width="410"。