C#でのpdf 印刷のための用紙方向を設定する方法
用紙の向きは、ドキュメントが縦(高さ)か横(幅)のモードで印刷されるかを制御します。 縦はほとんどの手紙、請求書、レポートに適しています。 横は、広いテーブル、スプレッドシート、ダッシュボード、およびプレゼンテーションスライドに最適です。 プログラムでの向き設定により、ユーザーのデフォルトプリンタ設定に関係なく一貫した出力が保証されます。
IronPrint は、PrintSettings クラス上で PaperOrientation プロパティを公開します。 それを 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()に渡す - 指定された向きで印刷するプロジェクトを実行する
印刷用紙の向きを設定するにはどうすればよいですか?
PrintSettingsのPaperOrientationプロパティは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;
// Portrait orientation — standard for letters and invoices
var portraitSettings = new PrintSettings
{
PaperOrientation = PaperOrientation.Portrait
};
Printer.Print("invoice.pdf", portraitSettings);
// Landscape orientation — ideal for wide tables and dashboards
var landscapeSettings = new PrintSettings
{
PaperOrientation = PaperOrientation.Landscape
};
Printer.Print("quarterly-dashboard.pdf", landscapeSettings);
Imports IronPrint
' Portrait orientation — standard for letters and invoices
Dim portraitSettings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Portrait
}
Printer.Print("invoice.pdf", portraitSettings)
' Landscape orientation — ideal for wide tables and dashboards
Dim landscapeSettings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Landscape
}
Printer.Print("quarterly-dashboard.pdf", landscapeSettings)
ネイティブ for .NETSystem.Drawing.Printingアプローチでは、向きは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;
var settings = new PrintSettings
{
PaperOrientation = PaperOrientation.Landscape,
PaperSize = PaperSize.A4,
Dpi = 300,
NumberOfCopies = 1,
PaperMargins = new Margins(15, 15, 15, 15),
Grayscale = false
};
Printer.Print("financial-report.pdf", settings);
Imports IronPrint
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
}
Printer.Print("financial-report.pdf", settings)
PaperOrientationは一緒に動作し、A4横は297×210 mmの印刷領域を提供し、A4縦は210×297 mmを提供します。 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-select landscape, but let the user override in the dialog
var settings = new PrintSettings
{
PaperOrientation = PaperOrientation.Landscape,
PaperSize = PaperSize.Letter
};
Printer.ShowPrintDialog("wide-report.pdf", settings);
Imports IronPrint
' Pre-select landscape, but let the user override in the dialog
Dim settings As New PrintSettings With {
.PaperOrientation = PaperOrientation.Landscape,
.PaperSize = PaperSize.Letter
}
Printer.ShowPrintDialog("wide-report.pdf", settings)
非ブロッキングなUIシナリオでは、非同期バリアントPrinter.ShowPrintDialogAsync()は同じパラメータを受け取り、ダイアログが開いている間アプリケーションが応答可能な状態を保ちます。 これは特に向きに有用です。ユーザーは印刷実行を決定する前にドキュメントが縦と横でどのように見えるかをプレビューしたいと望むことが多いためです。 印刷ドキュメントチュートリアルは、サイレントとダイアログワークフローのエンドツーエンドをカバーしています。
次のステップ
用紙の向きはAutomaticに設定して、任意のIronPrint印刷方法に渡します。 完全なレイアウト制御のためにPaperMarginsと組み合わせる。
印刷設定の方法に関するガイドで利用可能なすべてのプロパティを探索し、PrinterクラスAPIリファレンスで完全な方法の範囲を、またはコード例のページで実行可能なスニペットを確認します。 IronPrintチュートリアルでは、印刷のライフサイクル全体を説明し、更新履歴でパフォーマンス改善を含む最近の更新を追跡します。
30日間の無料トライアルを開始して、ライブプロジェクトでの向き設定をテストしてください。 準備ができたら、ライセンスオプションを表示し、749ドルから始めてください。

