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

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

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

IronPrint は、PrintSettings クラス上で PaperOrientation プロパティを公開します。 それを Portrait または Landscape に設定し、Printer.Print() に設定を渡すと、指定されたレイアウトでドキュメントを印刷します。

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

  1. NuGetを介してIronPrintをインストール: Install-Package IronPrint
  2. using IronPrint; をファイルに追加
  3. PrintSettings オブジェクトを作成
  4. PaperOrientationPortrait または Landscape に設定
  5. Printer.Print() または 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

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

PrintSettingsPaperOrientationプロパティは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)
$vbLabelText   $csharpLabel

ネイティブ 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)
$vbLabelText   $csharpLabel

PaperOrientationは一緒に動作し、A4横は297×210 mmの印刷領域を提供し、A4縦は210×297 mmを提供します。 PaperMarginsの値はミリメートルです。

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

我々がPrintSettingsPrinter.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)
$vbLabelText   $csharpLabel

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

次のステップ

用紙の向きはAutomaticに設定して、任意のIronPrint印刷方法に渡します。 完全なレイアウト制御のためにPaperMarginsと組み合わせる。

印刷設定の方法に関するガイドで利用可能なすべてのプロパティを探索し、PrinterクラスAPIリファレンスで完全な方法の範囲を、またはコード例のページで実行可能なスニペットを確認します。 IronPrintチュートリアルでは、印刷のライフサイクル全体を説明し、更新履歴でパフォーマンス改善を含む最近の更新を追跡します。

30日間の無料トライアルを開始して、ライブプロジェクトでの向き設定をテストしてください。 準備ができたら、ライセンスオプションを表示し、749ドルから始めてください。

カーティス・チャウ
テクニカルライター

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

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

準備はできましたか?
Nuget ダウンロード 38,930 | バージョン: 2026.4 リリース
Still Scrolling Icon

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

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