打印用户控制在顶部和左侧切断半英寸

时间:2013-08-22 20:12:21

标签: c# wpf printing

我有一个我想要打印的自定义控件。我已经尝试更改窗口上的边距以“缩进”我的控件,但它仍然会切断左侧和顶部。我也在我的打印方法中尝试了以下内容:

private void bttnPrint_Click(object sender, RoutedEventArgs e)
{
    UserControl hddc = HDDC;

    var printDlg = new PrintDialog
        {PrintTicket = {PageOrientation = PageOrientation.Landscape, PageBorderless = PageBorderless.Unknown}};

    //printDlg.PrintTicket.PageMediaSize.PageMediaSizeName = PageMediaSizeName.NorthAmerica11x17;

    if (printDlg.ShowDialog() == true)
    {

        printDlg.PrintVisual(hddc, "HDDC Report");
    }
    else
    {
        MessageBox.Show("Print Canceled");
    }
}

仍然,没有快乐。我感觉有一种愚蠢的设置我不知道,但我似乎无法找到它。为什么我的打印件会在顶部和左侧切断?

1 个答案:

答案 0 :(得分:0)

public void Printing() {
   try {
     streamToPrint = new StreamReader (filePath);
     try {
       PrintDocument prd = new PrintDocument(); 
       prd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
       prd.PrinterSettings.PrinterName = printer;
       // Set the page orientation to landscape.
       prd.DefaultPageSettings.Landscape = true;
       prd.Print();
     } 
     finally {
       streamToPrint.Close() ;
     }
   } 
   catch(Exception ex) { 
     MessageBox.Show(ex.Message);
   }
 }

命名空间:System.Drawing.Printing

或者这个链接可以帮到你 Page truncate in right side for landscape orientation with trimmargins using PdfSharp