C#でPDFの印刷設定を構成する方法 | IronPrint

How to Configure Print Settings

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

印刷設定とは、ドキュメントやコンテンツをどのように印刷するかを指示する構成またはパラメータのセットを指します。 これらの設定には、用紙サイズ、方向(例:縦または横)、印刷解像度(dpi)、コピーの数、プリンターの選択、余白、グレースケール印刷などのオプションが含まれます。 ユーザーはこれらの設定をカスタマイズして、特定の印刷の好みや要件を達成できます。

見出し:2(クイックスタート: IronPrint設定を使用した構成と印刷)

用紙サイズ、方向、DPI、コピー、グレースケールなどのプロパティをいくつか設定するだけで、PrintSettingsオブジェクトを作成することで簡単に始めることができます。 その後、Printer.Print(...)を呼び出して、これらの設定を即座に適用することができます — 複雑なセットアップは不要です。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPrint with NuGet Package Manager

    PM > Install-Package IronPrint

  2. Copy and run this code snippet.

    IronPrint.Printer.Print("document.pdf", new IronPrint.PrintSettings { PaperSize = IronPrint.PaperSize.A4, PaperOrientation = IronPrint.PaperOrientation.Landscape, Dpi = 300, NumberOfCopies = 2, Grayscale = true });
  3. Deploy to test on your live environment

    Start using IronPrint in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小限のワークフロー (5ステップ)

  1. 印刷設定を構成するためのC#ライブラリをダウンロード
  2. PrintSettingsクラスをインスタンス化
  3. PrintSettingsオブジェクトを好みに合わせて構成
  4. PrintまたはShowPrintDialogメソッドに渡します
  5. 印刷されたPDFドキュメントを確認して、印刷設定が適用されていることを確認

印刷設定を設定する

印刷設定を構成するには、PrintSettingsクラスをインスタンス化し、好みに合わせてそれを構成します。 PrintまたはShowPrintDialogメソッドで、PrintSettingsオブジェクトを第2パラメーターとして渡します。 以下のコード例では、この使用法を示しています。

// Import the necessary namespace for IronPrint
using IronPrint;

// Initialize a new instance of the PrintSettings class
PrintSettings settings = new PrintSettings();

// Configure various print settings
settings.PaperSize = PaperSize.A4;                // Set paper size to A4
settings.PaperOrientation = PaperOrientation.Landscape; // Set paper orientation to Landscape
settings.Dpi = 300;                               // Set print resolution to 300 DPI
settings.NumberOfCopies = 2;                      // Set the number of copies to 2
settings.PrinterName = "MyPrinter";               // Set the name of the printer
settings.PaperMargins = new Margins(10, 10, 10, 10); // Set margins to 10mm on each side
settings.Grayscale = true;                        // Print in grayscale

// Use the PrintSettings in the Print method
IronPrint.Printer.Print(document, settings);
// Import the necessary namespace for IronPrint
using IronPrint;

// Initialize a new instance of the PrintSettings class
PrintSettings settings = new PrintSettings();

// Configure various print settings
settings.PaperSize = PaperSize.A4;                // Set paper size to A4
settings.PaperOrientation = PaperOrientation.Landscape; // Set paper orientation to Landscape
settings.Dpi = 300;                               // Set print resolution to 300 DPI
settings.NumberOfCopies = 2;                      // Set the number of copies to 2
settings.PrinterName = "MyPrinter";               // Set the name of the printer
settings.PaperMargins = new Margins(10, 10, 10, 10); // Set margins to 10mm on each side
settings.Grayscale = true;                        // Print in grayscale

// Use the PrintSettings in the Print method
IronPrint.Printer.Print(document, settings);
' Import the necessary namespace for IronPrint
Imports IronPrint

' Initialize a new instance of the PrintSettings class
Private settings As New PrintSettings()

' Configure various print settings
settings.PaperSize = PaperSize.A4 ' Set paper size to A4
settings.PaperOrientation = PaperOrientation.Landscape ' Set paper orientation to Landscape
settings.Dpi = 300 ' Set print resolution to 300 DPI
settings.NumberOfCopies = 2 ' Set the number of copies to 2
settings.PrinterName = "MyPrinter" ' Set the name of the printer
settings.PaperMargins = New Margins(10, 10, 10, 10) ' Set margins to 10mm on each side
settings.Grayscale = True ' Print in grayscale

' Use the PrintSettings in the Print method
IronPrint.Printer.Print(document, settings)
$vbLabelText   $csharpLabel

利用可能な印刷設定

利用可能な全ての印刷設定オプションを以下で探索してください:

  • DefaultSettings: デフォルト値でIronPrint.PrintSettingsクラスの新しいインスタンスを初期化します。
  • PaperSize: プリンターで使用する用紙サイズを設定します。 デフォルト値はIronPrint.PaperSize.PrinterDefaultです。
  • PaperOrientation: 用紙の方向を指定します (例:縦または横)。 デフォルト値はIronPrint.PaperOrientation.Portraitです。
  • Dpi: インチあたりのドットで印刷解像度を表します。 デフォルト値は300です。これは商業印刷で一般的に使用される設定です。 注:印刷に使用される実際のDPIは、プリンターの能力によって制限される可能性があります。
  • NumberOfCopies: ドキュメントを印刷する際に生成される同一コピーの数を示します。 デフォルト値は1コピーです。 注:特定のプラットフォームでは、複数のコピーの正確な再現を妨げる制限が存在する可能性があります。 このような場合、指定されたIronPrint.PrintSettings.NumberOfCopiesの値は無視され、1コピーのみ印刷される可能性があります。
  • PrinterName: 印刷に使用するプリンターの名前を指定します。 デフォルト値はnullであり、オペレーティングシステムの現在のデフォルトプリンターが使用されます。 注:PrintDialogでプリンターを選択した場合、この設定は無視されます。 利用可能なプリンター名を取得するには、IronPrint.Printer.GetPrinterNamesまたはIronPrint.Printer.GetPrinterNamesAsyncを使用してプリンター名リストを取得できます。
  • PaperMargins: 印刷に使用する余白をミリメートルで設定します。 デフォルト値はnullであり、プリンターが提供するデフォルトの余白が使用されます。
  • Grayscale: グレースケールで印刷するかどうかを示します。 注:デフォルト値はfalseであり、カラー印刷が試みられます。
  • Flatten: PDFを印刷前にフラット化します。これはフォームフィールドの値や画像を表示するのに便利です。 デフォルト値はfalseであり、印刷前にPDFがフラット化されることを示しています。
  • Tray: 印刷ジョブに使用するプリンタートレイ。 これにより、用紙をプリンタに供給するために特定のトレイを指定することができます。 PrintDialogでトレイを選択した場合、この設定は無視されます。 利用可能なトレイを取得するには、IronPrint.Printer.GetPrinterTrays(System.String) または IronPrint.Printer.GetPrinterTraysAsync(System.String) を使用できます。 デフォルト値はnullで、プリンタが提供するデフォルトのトレイを使用することを示します。 このトレイ選択プロパティはWindowsでのみ利用可能です。

よくある質問

C#で印刷設定を構成する方法は?

C#で印刷設定を構成するには、IronPrintライブラリを使用できます。まず、PrintSettingsクラスをインスタンス化し、紙サイズ、向き、DPIなどの希望のパラメータを設定します。次に、構成したPrintSettingsオブジェクトをPrintまたはShowPrintDialogメソッドに渡します。

印刷に利用可能な紙サイズは何ですか?

IronPrintでは、PrintSettingsクラスのPaperSizeプロパティを通じてさまざまな紙サイズを設定できます。デフォルトではIronPrint.PaperSize.PrinterDefaultに設定されていますが、A4、レターサイズなどにカスタマイズできます。

印刷されたドキュメントの向きを変更できますか?

はい、PrintSettingsクラスのPaperOrientationプロパティを設定することで向きを変更できます。PortraitおよびLandscapeの向きがサポートされています。

印刷解像度(DPI)を調整するにはどうすればよいですか?

IronPrintでは、PrintSettingsクラスのDpiプロパティを設定することで印刷解像度を調整できます。デフォルトの解像度は300 DPIです。

IronPrintを使用して複数のコピーを印刷することは可能ですか?

はい、PrintSettingsクラスのNumberOfCopiesプロパティを設定することで、印刷するコピー数を指定できます。ただし、一部のプラットフォームではこの機能に影響を与える制限があるかもしれません。

特定のプリンターを印刷ジョブに選択するにはどうすればよいですか?

特定のプリンターを選択するには、PrintSettingsクラスのPrinterNameプロパティを設定します。プリンターが指定されていない場合は、デフォルトのシステムプリンターが使用されます。

印刷用のマージンを構成できますか?

はい、PrintSettingsクラスのPaperMarginsプロパティに希望のミリメートル値を設定することで印刷マージンを構成できます。

文書をグレースケールで印刷するにはどうすればよいですか?

PrintSettingsクラスのGrayscaleプロパティをtrueに設定してグレースケールで印刷します。デフォルト設定はfalseで、カラー印刷を試みます。

Flattenプロパティは何をしますか?

IronPrintのFlattenプロパティは、印刷前にPDFをフラット化するために使用されます。このプロセスは、フォームフィールドや画像が印刷物にきちんと表示されるようにするために役立ちます。

印刷ジョブのためにプリンタートレイを指定するにはどうすればよいですか?

プリンタートレイを指定するには、PrintSettingsクラスのTrayプロパティを設定します。ただし、PrintDialogでトレイが選択された場合、このプロパティは無視されます。IronPrintはGetPrinterTraysのような方法で利用可能なトレイをリストする方法を提供します。

Chaknith Bin
ソフトウェアエンジニア
ChaknithはIronXLとIronBarcodeに取り組んでいます。彼はC#と.NETの深い専門知識を持ち、ソフトウェアの改善や顧客サポートに貢献しています。ユーザーとの対話から得られる洞察が、より良い製品、ドキュメント、および全体的な経験に寄与しています。
準備はいいですか?
Nuget ダウンロード 34,016 | バージョン: 2025.11 ただ今リリースされました