印刷設定ダイアログを表示させると、コードから指定した給紙トレイの設定が反映されない

文書番号 : 35076     文書種別 : 不具合     登録日 : 2013/02/05     最終更新日 : 2013/04/17
文書を印刷する
対象製品
ActiveReports for .NET 7.0J
状況
修正済み
詳細
※この現象はセクションレポートおよびページレポートの両方で発生します。

Printer.DefaultPageSettings.PaperSourceプロパティなどを使用するとコード上から印刷時の給紙トレイをあらかじめ指定することが可能ですが、その印刷時に印刷設定ダイアログを表示させると、指定した給紙トレイが反映されません。

Printメソッドの第一引数を"False"に設定して印刷を行った場合、印刷設定ダイアログを表示せずに印刷されるため、本現象は発生しません。

セクションレポートの場合


◆サンプルコード(VB.NET)
Dim rpt As New NewActiveReport1

' 手差し(トレイ)を設定します。
For Each ps As System.Drawing.Printing.PaperSource In rpt.Document.Printer.PrinterSettings.PaperSources
  If ps.SourceName = "手差し(トレイ)" Then
    rpt.PageSettings.DefaultPaperSource = False
    rpt.PageSettings.PaperSource = ps.Kind
    rpt.Document.Printer.DefaultPageSettings.PaperSource = ps
    Exit For
  End If
Next

rpt.Run()
rpt.Document.Print()
'rpt.Document.Print(False) ' 印刷ダイアログを表示しない場合、現象は発生しません。


◆サンプルコード(C#)
NewActiveReport1 rpt = new NewActiveReport1();

// 手差し(トレイ)を設定します。
foreach (System.Drawing.Printing.PaperSource ps in rpt.Document.Printer.PrinterSettings.PaperSources)
{
  if (ps.SourceName == "手差し(トレイ)")
  {
    rpt.PageSettings.DefaultPaperSource = false;
    rpt.PageSettings.PaperSource = ps.Kind;
    rpt.Document.Printer.DefaultPageSettings.PaperSource = ps;
    break;
  }
}

rpt.Run();
rpt.Document.Print();
//rpt.Document.Print(false); // 印刷ダイアログを表示しない場合、現象は発生しません。


ページレポートの場合


◆サンプルコード(VB.NET)
Dim rpt As New GrapeCity.ActiveReports.PageReport()
rpt.Load(New System.IO.FileInfo("PageReport1.rdlx"))
Dim pageDocument As New GrapeCity.ActiveReports.Document.PageDocument(rpt)

' 手差し(トレイ)を設定します。
For Each ps As System.Drawing.Printing.PaperSource In pageDocument.Printer.PrinterSettings.PaperSources
  If ps.SourceName = "手差し(トレイ)" Then
    pageDocument.Printer.DefaultPageSettings.PaperSource = ps
    Exit For
  End If
Next

pageDocument.Print()
'pageDocument.Print(False) ' 印刷ダイアログを表示しない場合、現象は発生しません。


◆サンプルコード(C#)
GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport();
rpt.Load(new System.IO.FileInfo("PageReport1.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(rpt);

// 手差し(トレイ)を設定します。
foreach (System.Drawing.Printing.PaperSource ps in pageDocument.Printer.PrinterSettings.PaperSources)
{
  if (ps.SourceName == "手差し(トレイ)")
  {
    pageDocument.Printer.DefaultPageSettings.PaperSource = ps;
    break;
  }
}

pageDocument.Print();
//pageDocument.Print(false); // 印刷ダイアログを表示しない場合、現象は発生しません。
回避方法
この問題はService Pack 1(v7.1.7470.1)で修正されました。
不具合を修正した最新のサービスパックは、アップデートページ からダウンロードできます。

初版(v7.0.6257.1)利用時は以下の方法で回避可能です。
.NET標準の印刷設定ダイアログ(System.Windows.Forms.PrintDialog)を使用する方法が考えられます。

ただし、この方法の場合、ページ設定ダイアログ(印刷時に複数ページを1枚の用紙に出力する設定やマージン指定、ウォーターマークを出力指定ができる)は利用できません。

詳細については、以下のKB文書にある「2. .NET標準の印刷設定ダイアログ(System.Windows.Forms.PrintDialog)を使用する方法」のコードをご覧ください。

Windowsフォームアプリでレポートを印刷する際、印刷ダイアログ上で押されたボタンを判断する方法は?
キーワード
09326