C#での印刷のための用紙方向を設定する方法
用紙の向きは、ドキュメントが縦(高さ)か横(幅)のモードで印刷されるかを制御します。 縦はほとんどの手紙、請求書、レポートに適しています。 横は、広いテーブル、スプレッドシート、ダッシュボード、およびプレゼンテーションスライドに最適です。 プログラムでの向き設定により、ユーザーのデフォルトプリンタ設定に関係なく一貫した出力が保証されます。
IronPrintはPaperOrientationプロパティを公開しています。 それをPrinter.Print()に渡すと、指定されたレイアウトでドキュメントが印刷されます。
- NuGet経由で
IronPrintをインストール:Install-Package IronPrint - ファイルに
using IronPrint;を追加 PrintSettingsオブジェクトを作成Landscapeに設定- 設定を
Printer.ShowPrintDialog()に渡す
-
1Install IronPrint with NuGet Package Manager
-
2このコード スニペットをコピーして実行します。
using IronPrint; // Print a document in landscape orientation Printer.Print("report.pdf", new PrintSettings { PaperOrientation = PaperOrientation.Landscape });Imports IronPrint ' Print a document in landscape orientation Printer.Print("report.pdf", New PrintSettings With { .PaperOrientation = PaperOrientation.Landscape })Imports IronPrint ' Print a document in landscape orientation Printer.Print("report.pdf", New PrintSettings With { .PaperOrientation = PaperOrientation.Landscape }) -
3実際の環境でテストするためにデプロイする
今日プロジェクトで IronPrint を使い始めましょう無料トライアル
最小限のワークフロー(5ステップ)
- IronPrint C#印刷ライブラリをインストール
PrintSettingsオブジェクトを作成PaperOrientationをPortraitまたはLandscapeに設定する- 設定を
Printer.Print()に渡す - 指定された向きで印刷するプロジェクトを実行する
印刷用紙の向きを設定するにはどうすればよいですか?
PaperOrientationプロパティは3つの値を受け取ります:
PaperOrientation.Portrait- 縦向きレイアウト(ほとんどのプリンターでデフォルト)です。 手紙、契約書、請求書のような単一カラムのドキュメントに最適です。PaperOrientation.Landscape- 横向きレイアウトです。 データテーブル、ガントチャート、スプレッドシート、スライドデッキのような広い内容に最適です。PaperOrientation.Automatic- プリンターのデフォルト設定に委ねます。
私たちはPrintSettingsオブジェクトを作成し、希望の向きを設定して、無音印刷のためにPrinter.Print()に、またはダイアログベースの印刷のためにPrinter.ShowPrintDialog()に渡します。
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);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)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)ネイティブ for .NETPrintPageイベント処理、グラフィックレンダリング、手動ページ管理が必要です。 IronPrintは設定オブジェクト上の単一プロパティでその全体のパイプラインを置き換えます。
他の印刷設定と向きを組み合わせるにはどうしますか?
用紙サイズ、DPI、および余白と組み合わせると、完全な印刷レイアウトを定義する際に、向きが最も有用です。 PrintSettingsクラスは、これらすべてを1つのオブジェクトで構成することができます。
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);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)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)PaperOrientationは連携します - A4横向きに設定すると297 × 210 mmの印刷領域になり、A4縦向きは210 × 297 mmになります。 PaperMarginsの値はミリメートル単位です。
印刷ダイアログでユーザーが向きを選択できるようにするにはどうしますか?
私たちがPrinter.ShowPrintDialog()に渡すと、ダイアログは私たちのプリセット向きで開きます。 ユーザーはそれを受け入れるか、印刷前に縦と横の間で切り替えることができます。
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);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)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()は同じパラメーターを受け入れ、ダイアログが開いている間もアプリケーションを応答性を保ちます。 これは特に向きに有用です。ユーザーは印刷実行を決定する前にドキュメントが縦と横でどのように見えるかをプレビューしたいと望むことが多いためです。 印刷ドキュメントチュートリアルは、サイレントとダイアログワークフローのエンドツーエンドをカバーしています。
次のステップ
紙の向きは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プロパティを活用して、縦、横、自動モードを指定することで、用紙の向きを完全にコントロールできます。
Does IronPrint support async operations for user interaction in print dialogs?
Yes, IronPrint supports asynchronous operations through Printer.ShowPrintDialogAsync(), allowing the application to remain responsive while the print dialog is open, which is useful for scenarios where users need to preview document orientation options.
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。