C#での印刷のための用紙方向を設定する方法
用紙の向きは、ドキュメントが縦(高さ)か横(幅)のモードで印刷されるかを制御します。 縦はほとんどの手紙、請求書、レポートに適しています。 横は、広いテーブル、スプレッドシート、ダッシュボード、およびプレゼンテーションスライドに最適です。 プログラムでの向き設定により、ユーザーのデフォルトプリンタ設定に関係なく一貫した出力が保証されます。
IronPrint は PaperOrientation プロパティを PrintSettings クラス上に公開します。 それを Portrait または Landscape に設定し、Printer.Print() に設定を渡すと、指定されたレイアウトでドキュメントが印刷されます。
- NuGet 経由で
IronPrintをインストール:Install-Package IronPrint - ファイルに
using IronPrint;を追加 PrintSettingsオブジェクトを作成PaperOrientationをPortraitまたはLandscapeに設定- 設定を
Printer.Print()またはPrinter.ShowPrintDialog()に渡す
-
1IronPrint を 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 プロパティは PrintSettings 上で以下の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)ネイティブ .NET System.Drawing.Printing アプローチでは、向きは DefaultPageSettings.Landscape = true に埋め込まれたブール値であり、PrintDocument もまた、PrintPage イベントハンドリング、グラフィックレンダリング、および手動ページ管理を必要とします。 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)PaperSize と PaperOrientation は連携して動作します - A4 横向きを設定すると297 × 210 mmの印刷領域が得られ、A4 縦向きを設定すると210 × 297 mmが得られます。 Dpi プロパティは出力解像度を制御し(300はビジネス文書の標準)、PaperMargins の値はミリメートルです。
印刷ダイアログでユーザーが向きを選択できるようにするにはどうしますか?
PrintSettings を 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() が同じパラメータを受け入れ、ダイアログが開いている間もアプリケーションの応答性を保ちます。 これは特に向きに有用です。ユーザーは印刷実行を決定する前にドキュメントが縦と横でどのように見えるかをプレビューしたいと望むことが多いためです。 印刷文書チュートリアル は、サイレントとダイアログのワークフローを完全にカバーしています。
次のステップ
用紙の向きは PrintSettings オブジェクトの1つのプロパティです - PaperOrientation を Portrait、Landscape、または Automatic に設定し、任意の IronPrint の印刷メソッドに渡します。 PaperSize、Dpi、PaperMargins と組み合わせて、完全なレイアウト制御を実現します。
印刷設定のハウツー で使用可能なすべてのプロパティを調べたり、Printer クラスAPIリファレンス で完全なメソッド表面を確認したり、コード例ページ で実行可能なスニペットを調べたりしてください。 IronPrint チュートリアル は完全な印刷ライフサイクルを案内し、変更履歴 は性能向上を含む最近の更新を追跡します。
無料で30日間トライアルを開始 し、ライブプロジェクトでの向き設定をテストしてください。 準備ができたら、$999 から始まるライセンスオプションを表示してください。
よくある質問
C# で印刷のための用紙の向きをどのように設定できますか?
IronPrint を使用して C# で用紙の向きを設定するには、PrintSettings クラスの PaperOrientation プロパティを使用します。縦方向のレイアウトには Portrait、横方向のレイアウトには Landscape を設定できます。これらの設定を Printer.Print() に渡すことで、指定された向きでドキュメントが印刷されます。
IronPrint で利用可能な用紙の向きのオプションは何ですか?
IronPrint は PaperOrientation の3つのオプションを提供します: Portrait、Landscape、および Automatic。Portrait は手紙のような縦型のドキュメントに最適であり、Landscape はスプレッドシートのような横型のコンテンツに理想的です。Automatic はプリンターのデフォルトの向き設定に従います。
用紙の向きと一緒に他の印刷設定を変更できますか?
はい、IronPrint では、用紙サイズ、DPI、マージンなどの他の設定を、同じ PrintSettings オブジェクト内で構成することにより、向きと組み合わせることができます。これにより、印刷レイアウトを完全に制御できます。
印刷ダイアログを通じてユーザーが好みの向きを選ぶことは可能ですか?
はい、Printer.ShowPrintDialog() と事前に設定された PrintSettings オブジェクトを使用することで、ユーザーにはポートレートとランドスケープの向きを選択できるダイアログが表示されます。
プロジェクトで用紙の向きを管理するために IronPrint をどのようにインストールしますか?
IronPrint をインストールするには、NuGet を使用して Install-Package IronPrint コマンドを実行します。これにより、プロジェクトに必要なライブラリが追加され、用紙の向きやその他の印刷設定を制御できます。
IronPrint による用紙の向き設定は .NET のネイティブ System.Drawing.Printing と何が違いますか?
IronPrint は PrintPage イベントを処理しページレイアウトを管理するような複雑なネイティブメソッドを PrintSettings オブジェクトの PaperOrientation プロパティで置き換えることで、プロセスを簡素化しており、向きを設定するより簡単で効率的な方法を提供します。
IronPrint で向き設定をテストするためのトライアルをどのように開始しますか?
IronPrint の無料30日間トライアルは、ウェブサイトを訪れることで開始できます。これにより、購入を決定する前に、ライブプロジェクト内でさまざまな向き設定やその他の機能を探索しテストすることができます。
IronPrint は印刷ダイアログでのユーザーの操作を非同期でサポートしていますか?
はい、IronPrint は Printer.ShowPrintDialogAsync() を通じて非同期操作をサポートし、印刷ダイアログが開いている間もアプリケーションは応答性を保つことができ、ユーザーがドキュメントの向きオプションをプレビューする必要があるシナリオで役立ちます。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。