C#Printvisual,无法适合页面

时间:2015-03-29 15:18:40

标签: c# printing

我想使用printvisual打印此gridcontroll:

<Grid Name="printingkvitto2" Margin="0" Height="900" Width="842" VerticalAlignment="Top">
//stuff
</Grid>

得到这段代码:

PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
//if (printDlg.ShowDialog() == true)
{
    LocalPrintServer localPrintServer = new LocalPrintServer();
    PrintQueue pq = localPrintServer.GetPrintQueue(Properties.Settings.Default.valdskrivarenamn);
    printDlg.PrintQueue = pq;

    //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 / printingkvitto2.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                      printingkvitto2.ActualHeight);

    //Transform the Visual to scale
    printingkvitto2.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.
    printingkvitto2.Measure(sz);
    printingkvitto2.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(printingkvitto2, "print");
}

但我不能让它适合打印页面(A4)。它始终位于右侧框架之外。

我想向打印机发送“适合页面”设置。 我做错了什么?

0 个答案:

没有答案