現在、印刷しているユーザー コントロールに合わせて正しくスケーリングされた単一のページを印刷できます。ただし、ユーザー コントロールのサイズがページ サイズを超えているため、ユーザー コントロールの残りの部分を含む別のページを印刷する必要があります。これについてどうすればいいですか?固定ドキュメントを印刷するか、ビジュアルをビットマップにダンプして切り刻むことを検討しました。
private void Print( Visual v )
{
System.Windows.FrameworkElement e = v as System.Windows.FrameworkElement;
if( e == null )
return;
PrintDialog pd = new PrintDialog();
if( pd.ShowDialog() == true )
{
//store original scale
Transform originalScale = e.LayoutTransform;
//get selected printer capabilities
System.Printing.PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities( pd.PrintTicket );
//get scale of the print wrt to screen of WPF visual
double scaley = Math.Min( capabilities.PageImageableArea.ExtentWidth / e.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
e.ActualHeight );
double scalex = Math.Max( capabilities.PageImageableArea.ExtentWidth / e.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
e.ActualHeight );
//Transform the Visual to scale
e.LayoutTransform = new ScaleTransform( 0.2823293807641634 + 0.2498215560314061, 0.2823293807641634 + 0.2498215560314061 );
//get the size of the printer page
System.Windows.Size sz = new System.Windows.Size( capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight );
//update the layout of the visual to the printer page size.
e.Measure( sz );
e.Arrange( new System.Windows.Rect( new System.Windows.Point( capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight ), sz ) );
//now print the visual to printer to fit on the one page.
pd.PrintVisual( v, "My Print" );
//apply the original transform.
e.LayoutTransform = originalScale;
}
}
private void UserControl_Loaded( object sender, RoutedEventArgs e )
{
Print( this.gdOuterReport );
}