我有 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");
}