2011-09-12 4 views
2

WPF의 PrintDialog 클래스 (PresentationFramework.dll의 System.Windows.Controls 네임 스페이스, v4.0.30319)로 인쇄하려고합니다. 이것은 내가 사용하는 코드입니다 :PrintDialog/XPS 문서 기록기에서 무시 된 용지 크기

private void PrintMe() 
{ 
    var dlg = new PrintDialog(); 

    if (dlg.ShowDialog() == true) 
    { 
     dlg.PrintVisual(new System.Windows.Shapes.Rectangle 
     { 
      Width = 100, 
      Height = 100, 
      Fill = System.Windows.Media.Brushes.Red 
     }, "test"); 
    } 
} 

문제는 아무리 내가 "마이크로 소프트 XPS 문서 작성자"를 선택 무엇 용지 크기, 생성 된 XPS는 항상 "편지"의 폭과 높이를주지 않습니다 용지 종류 :

이것은 내가 XPS 패키지 내에서 찾을 수있는 XAML 코드 :

<FixedPage ... Width="816" Height="1056">

답변

2

가 인쇄 대화 상자에서 용지 크기를 변경에만 PrintTicket 아닌 FixedPage에 영향을 미칩니다 함유량. PrintVisual 메서드는 Letter 크기 페이지를 생성하므로 다른 페이지 크기를 사용하려면 PrintDocument 메서드를 사용해야합니다. 예 :

private void PrintMe() 
{ 
    var dlg = new PrintDialog(); 
    FixedPage fp = new FixedPage(); 
    fp.Height = 100; 
    fp.Width = 100; 
    fp.Children.Add(new System.Windows.Shapes.Rectangle 
     { 
      Width = 100, 
      Height = 100, 
      Fill = System.Windows.Media.Brushes.Red 
     }); 
    PageContent pc = new PageContent(); 
    pc.Child = fp; 
    FixedDocument fd = new FixedDocument(); 
    fd.Pages.Add(pc); 
    DocumentReference dr = new DocumentReference(); 
    dr.SetDocument(fd); 
    FixedDocumentSequence fds = new FixedDocumentSequence(); 
    fds.References.Add(dr);    

    if (dlg.ShowDialog() == true) 
    { 
     dlg.PrintDocument(fds.DocumentPaginator, "test"); 
    } 
}