C#での印刷のための用紙方向を設定する方法

This article was translated from English: Does it need improvement?
Translated
View the article in English

用紙の向きは、ドキュメントが縦(高さ)か横(幅)のモードで印刷されるかを制御します。 縦はほとんどの手紙、請求書、レポートに適しています。 横は、広いテーブル、スプレッドシート、ダッシュボード、およびプレゼンテーションスライドに最適です。 プログラムでの向き設定により、ユーザーのデフォルトプリンタ設定に関係なく一貫した出力が保証されます。

IronPrintPaperOrientationプロパティを公開しています。 それをPrinter.Print()に渡すと、指定されたレイアウトでドキュメントが印刷されます。

クイックスタート: 用紙の向きを設定する

  1. NuGet経由でIronPrintをインストール: Install-Package IronPrint
  2. ファイルにusing IronPrint;を追加
  3. PrintSettingsオブジェクトを作成
  4. Landscapeに設定
  5. 設定をPrinter.ShowPrintDialog()に渡す
  1. IronPrint をNuGetパッケージマネージャでインストール

    PM > Install-Package IronPrint
  2. このコード スニペットをコピーして実行します。

    using IronPrint;
    
    // Print a document in landscape orientation
    Printer.Print("report.pdf", new PrintSettings
    {
        PaperOrientation = PaperOrientation.Landscape
    });
  3. 実際の環境でテストするためにデプロイする

    今日プロジェクトで IronPrint を使い始めましょう無料トライアル

    arrow pointer

印刷用紙の向きを設定するにはどうすればよいですか?

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;

// 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)
$vbLabelText   $csharpLabel

ネイティブ for .NETPrintPageイベント処理、グラフィックレンダリング、手動ページ管理が必要です。 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)
$vbLabelText   $csharpLabel

PaperOrientationは連携します — A4横向きに設定すると297 × 210 mmの印刷領域になり、A4縦向きは210 × 297 mmになります。 PaperMarginsの値はミリメートル単位です。

印刷ダイアログでユーザーが向きを選択できるようにするにはどうしますか?

私たちが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)
$vbLabelText   $csharpLabel

非ブロッキングUIシナリオのために、非同期バリアントPrinter.ShowPrintDialogAsync()は同じパラメーターを受け入れ、ダイアログが開いている間もアプリケーションを応答性を保ちます。 これは特に向きに有用です。ユーザーは印刷実行を決定する前にドキュメントが縦と横でどのように見えるかをプレビューしたいと望むことが多いためです。 印刷ドキュメントチュートリアルは、サイレントとダイアログワークフローのエンドツーエンドをカバーしています。

次のステップ

紙の向きは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プロパティを活用して、縦、横、自動モードを指定することで、用紙の向きを完全にコントロールできます。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 44,051 | バージョン: 2026.7 リリースされたばかり
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package IronPrint
サンプルを実行する プリンターに出力されるドキュメントを見る。