C#での印刷のための用紙方向を設定する方法
用紙の向きは、ドキュメントが縦(高さ)か横(幅)のモードで印刷されるかを制御します。 縦はほとんどの手紙、請求書、レポートに適しています。 横は、広いテーブル、スプレッドシート、ダッシュボード、およびプレゼンテーションスライドに最適です。 プログラムでの向き設定により、ユーザーのデフォルトプリンタ設定に関係なく一貫した出力が保証されます。
IronPrintは、PaperOrientationクラス上でPrintSettingsプロパティを公開しています。 これを Portrait または Landscape に設定し、設定を Printer.Print() に渡すと、ドキュメントは指定されたレイアウトで印刷されます。
クイックスタート: 用紙の向きを設定する
- NuGet 経由で
IronPrintをインストールします:Install-Package IronPrint - ファイルに
using IronPrint;を追加してください PrintSettingsオブジェクトを作成するPaperOrientationをPortraitまたはLandscapeに設定してください- 設定を
Printer.Print()またはPrinter.ShowPrintDialog()に渡す
-
IronPrint をNuGetパッケージマネージャでインストール
PM > Install-Package IronPrint -
このコード スニペットをコピーして実行します。
using IronPrint; // Print a document in landscape orientation Printer.Print("report.pdf", new PrintSettings { PaperOrientation = PaperOrientation.Landscape }); -
実際の環境でテストするためにデプロイする
今日プロジェクトで IronPrint を使い始めましょう無料トライアル
最小限のワークフロー(5ステップ)
- IronPrint C#印刷ライブラリをインストール
PrintSettingsオブジェクトを作成PaperOrientationをPortraitまたはLandscapeに設定する- 設定を
Printer.Print()に渡す - 指定された向きで印刷するプロジェクトを実行する
印刷用紙の向きを設定するにはどうすればよいですか?
PaperOrientation プロパティは、PrintSettings に対して 3 つの値を受け付けます:
PaperOrientation.Portrait— 縦書きレイアウト(ほとんどのプリンターでのデフォルト設定)。 手紙、契約書、請求書のような単一カラムのドキュメントに最適です。PaperOrientation.Landscape— 水平レイアウト。 データテーブル、ガントチャート、スプレッドシート、スライドデッキのような広い内容に最適です。PaperOrientation.Automatic— プリンターのデフォルト設定に従います。
PrintSettings オブジェクトを作成し、希望する向きを設定して、サイレント印刷の場合は Printer.Print() に、ダイアログベースの印刷の場合は Printer.ShowPrintDialog() に渡します。
:path=/static-assets/print/content-code-examples/how-to/set-paper-orientation/set-paper-orientation-portrait-and-landscape-orientation.cs
using IronPrint;
// Configure portrait orientation
var portraitSettings = new PrintSettings
{
PaperOrientation = PaperOrientation.Portrait
};
// Print the invoice in portrait
Printer.Print("invoice.pdf", portraitSettings);
// Configure landscape orientation
var landscapeSettings = new PrintSettings
{
PaperOrientation = PaperOrientation.Landscape
};
// Print the dashboard in landscape
Printer.Print("quarterly-dashboard.pdf", landscapeSettings);
Imports IronPrint
' Configure portrait orientation
Dim portraitSettings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Portrait
}
' Print the invoice in portrait
Printer.Print("invoice.pdf", portraitSettings)
' Configure landscape orientation
Dim landscapeSettings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Landscape
}
' Print the dashboard in landscape
Printer.Print("quarterly-dashboard.pdf", landscapeSettings)
ネイティブの .NET System.Drawing.Printing アプローチでは、向きは DefaultPageSettings.Landscape = true 内に埋め込まれたブール値 (PrintDocument) であり、これには PrintPage イベント処理、グラフィックスレンダリング、および手動によるページ管理も必要となります。 IronPrintは設定オブジェクト上の単一プロパティでその全体のパイプラインを置き換えます。
他の印刷設定と向きを組み合わせるにはどうしますか?
用紙サイズ、DPI、および余白と組み合わせると、完全な印刷レイアウトを定義する際に、向きが最も有用です。 PrintSettings クラスを使用すると、これらすべてを 1 つのオブジェクトで設定できます。
:path=/static-assets/print/content-code-examples/how-to/set-paper-orientation/set-paper-orientation-combine-orientation-with-settings.cs
using IronPrint;
// Combine orientation with paper size, DPI, and margins
var settings = new PrintSettings
{
PaperOrientation = PaperOrientation.Landscape,
PaperSize = PaperSize.A4,
Dpi = 300,
NumberOfCopies = 1,
PaperMargins = new Margins(15, 15, 15, 15),
Grayscale = false
};
// Print the financial report
Printer.Print("financial-report.pdf", settings);
Imports IronPrint
' Combine orientation with paper size, DPI, and margins
Dim settings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Landscape,
.PaperSize = PaperSize.A4,
.Dpi = 300,
.NumberOfCopies = 1,
.PaperMargins = New Margins(15, 15, 15, 15),
.Grayscale = False
}
' Print the financial report
Printer.Print("financial-report.pdf", settings)
PaperSize と PaperOrientation は連動しています。A4横向きに設定すると印刷領域は297 × 210 mmになり、A4縦向きに設定すると210 × 297 mmになります。 Dpi プロパティは出力解像度を制御します(ビジネス文書では 300 が標準です)。PaperMargins の値はミリメートル単位です。
印刷ダイアログでユーザーが向きを選択できるようにするにはどうしますか?
PrintSettings を Printer.ShowPrintDialog() に渡すと、ダイアログが事前設定された向きで開きます。 ユーザーはそれを受け入れるか、印刷前に縦と横の間で切り替えることができます。
:path=/static-assets/print/content-code-examples/how-to/set-paper-orientation/set-paper-orientation-dialog-with-orientation-preset.cs
using IronPrint;
// Pre-configure landscape orientation for the dialog
var settings = new PrintSettings
{
PaperOrientation = PaperOrientation.Landscape,
PaperSize = PaperSize.Letter
};
// Open the dialog with pre-selected orientation
Printer.ShowPrintDialog("wide-report.pdf", settings);
Imports IronPrint
' Pre-configure landscape orientation for the dialog
Dim settings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Landscape,
.PaperSize = PaperSize.Letter
}
' Open the dialog with pre-selected orientation
Printer.ShowPrintDialog("wide-report.pdf", settings)
ノンブロッキングな UI シナリオでは、非同期バージョンの Printer.ShowPrintDialogAsync() が同じパラメータを受け付け、ダイアログが開いている間もアプリケーションの応答性を維持します。 これは特に向きに有用です。ユーザーは印刷実行を決定する前にドキュメントが縦と横でどのように見えるかをプレビューしたいと望むことが多いためです。 印刷ドキュメントチュートリアルは、サイレントとダイアログワークフローのエンドツーエンドをカバーしています。
次のステップ
用紙の向きは PrintSettings オブジェクトのプロパティの 1 つです。PaperOrientation を Landscape、または Automatic に設定し、IronPrint の任意の印刷メソッドに渡してください。 完全なレイアウト制御を行うには、PaperMarginsと組み合わせて使用してください。
印刷設定の方法に関するガイドで利用可能なすべてのプロパティを探索し、PrinterクラスAPIリファレンスで完全な方法の範囲を、またはコード例のページで実行可能なスニペットを確認します。 IronPrintチュートリアルでは、印刷のライフサイクル全体を説明し、更新履歴でパフォーマンス改善を含む最近の更新を追跡します。
30日間の無料トライアルを開始して、ライブプロジェクトでの向き設定をテストしてください。 準備が整いましたら、$999から始まるライセンスオプションをご覧ください。
よくある質問
C#で印刷用紙の向きを設定するにはどうすれば良いですか?
C#で印刷用紙の向きを設定するには、IronPrintのPaperOrientationプロパティを使用します。これにより、ドキュメントが縦、横、または自動向きで印刷されるように指定できます。
IronPrintで利用できる用紙の向きオプションは何ですか?
IronPrintは用紙の向きを縦、横、または自動に設定するオプションを提供し、ドキュメントの印刷方法を完全にコントロールできます。
IronPrintで用紙の向きを自動的に決定できますか?
はい、IronPrintは自動向きを設定してドキュメントに最適な用紙の向きを自動的に決定できます。
IronPrintで用紙の向きを制御するために使用されるプロパティは何ですか?
IronPrintのPaperOrientationプロパティは、C#でドキュメント印刷用紙の向きを制御するために使用されます。
IronPrintは横向き印刷を処理できますか?
はい、IronPrintはPaperOrientationプロパティを横向きに設定することで横向き印刷を処理できます。
IronPrintはドキュメント印刷の縦モードをサポートしていますか?
IronPrintは、PaperOrientationプロパティを縦に設定することで、ドキュメント印刷の縦モードを完全にサポートしています。
IronPrintを使用してC#で用紙の向きを完全にコントロールするにはどうすれば良いですか?
IronPrintのPaperOrientationプロパティを活用して、縦、横、自動モードを指定することで、用紙の向きを完全にコントロールできます。

