IronPrintを使ってC#で印刷設定を構成する方法This article was translated from English: Does it need improvement? TranslatedView the article in EnglishIronPrintのPrintSettingsクラスを使ってC#で印刷設定を行い、用紙サイズ、向き、DPI、余白などをコントロールします。 PrintSettingsをインスタンス化し、好みを設定し、Printメソッドに渡すだけです。
クイックスタート: IronPrint 設定を使用して構成および印刷する
PrintSettingsオブジェクトを作成し、用紙サイズ、向き、DPI、コピー、グレースケールなどのプロパティを設定することから始めましょう。 次に、 Printer.Print(...)を呼び出してこれらの設定を即座に適用します。複雑な設定は必要ありません。
今すぐ NuGet で PDF を作成してみましょう:
NuGet パッケージ マネージャーを使用して IronPrint をインストールします
このコード スニペットをコピーして実行します。
IronPrint.Printer.Print("document.pdf", new IronPrint.PrintSettings { PaperSize = IronPrint.PaperSize.A4, PaperOrientation = IronPrint.PaperOrientation.Landscape, Dpi = 300, NumberOfCopies = 2, Grayscale = true });
実際の環境でテストするためにデプロイする
最小限のワークフロー(5ステップ)
- 印刷設定を構成するための C# ライブラリをダウンロードする
PrintSettingsクラスをインスタンス化します。- 好みに応じて
PrintSettingsオブジェクトを構成する。 - それを
PrintまたはShowPrintDialogメソッドに渡します - 印刷されたPDFドキュメントを確認し、印刷設定が適用されているか確認する
印刷設定はどのようにすればよいですか?
印刷設定を構成するには、PrintSettingsクラスをインスタンス化し、好みに応じて構成します。 PrintまたはShowPrintDialogメソッドでは、2番目のパラメータとしてPrintSettingsオブジェクトを渡します。 以下のコード例はこの使用方法を示しています。 より詳細な例については、印刷設定コード例ページを確認してください。
// 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);
$vbLabelText $csharpLabelなぜ印刷設定を構成する必要があるのですか?
印刷設定とは、ドキュメントまたはコンテンツの印刷方法を指定する構成またはパラメータのセットを指します。 これらの設定には、用紙サイズ、向き(縦または横)、印刷解像度(1インチあたりのドット数 - DPI)、部数、プリンタの選択、余白、グレースケール印刷などのオプションなどの詳細が含まれます。 特定の印刷の好みや要件を達成するために、これらの設定をカスタマイズします。
IronPrintの包括的な印刷設定機能は、開発者に印刷プロセスのあらゆる側面をきめ細かくコントロールすることを提供します。 デスクトップアプリケーションを構築する場合でも、ASP.NET Webアプリケーションを構築する場合でも、適切な設定を行うことで、異なる環境でも一貫した結果を得ることができます。
カスタム印刷設定はいつ使うべきですか?
カスタム印刷設定は、印刷出力を正確に制御する必要がある場合に不可欠です。たとえば、特定の余白を使用してレポートを印刷する場合、複数部のドキュメントを生成する場合、ビジネスニーズに合わせてドキュメントを正しい向きで印刷する場合などです。
ここでは、特定の要件を満たす請求書を印刷するための実用的な例を紹介します:
// Example: Printing invoices with business requirements
using IronPrint;
// Invoice printing with specific business settings
var invoiceSettings = new PrintSettings
{
PaperSize = PaperSize.Letter, // US Letter size for business documents
PaperOrientation = PaperOrientation.Portrait,
Dpi = 600, // High quality for professional output
NumberOfCopies = 3, // Original + customer copy + file copy
PaperMargins = new Margins(15, 15, 15, 25), // Extra bottom margin for footer
Grayscale = false, // Keep company logo in color
PrinterName = "Office Color Printer" // Specific high-quality printer
};
// Print the invoice
Printer.Print("invoice_2024_001.pdf", invoiceSettings);
// Example: Printing invoices with business requirements
using IronPrint;
// Invoice printing with specific business settings
var invoiceSettings = new PrintSettings
{
PaperSize = PaperSize.Letter, // US Letter size for business documents
PaperOrientation = PaperOrientation.Portrait,
Dpi = 600, // High quality for professional output
NumberOfCopies = 3, // Original + customer copy + file copy
PaperMargins = new Margins(15, 15, 15, 25), // Extra bottom margin for footer
Grayscale = false, // Keep company logo in color
PrinterName = "Office Color Printer" // Specific high-quality printer
};
// Print the invoice
Printer.Print("invoice_2024_001.pdf", invoiceSettings);
$vbLabelText $csharpLabel印刷設定を指定しないとどうなりますか?
印刷設定が指定されていない場合、IronPrintはシステムのデフォルトプリンターのデフォルト設定を使用します。 システム上で利用可能なプリンタを検出するには、GetPrinterNames メソッドを使用して、接続されているすべてのプリンタをプログラムで取得します。
どのような印刷設定が可能ですか?
IronPrintのPrintSettingsクラスを使ってC#で印刷設定を行い、用紙サイズ、向き、DPI、余白などをコントロールします。 PrintSettingsをインスタンス化し、好みを設定し、Printメソッドに渡すだけです。
クイックスタート: IronPrint 設定を使用して構成および印刷する
PrintSettingsオブジェクトを作成し、用紙サイズ、向き、DPI、コピー、グレースケールなどのプロパティを設定することから始めましょう。 次に、 Printer.Print(...)を呼び出してこれらの設定を即座に適用します。複雑な設定は必要ありません。
今すぐ NuGet で PDF を作成してみましょう:
NuGet パッケージ マネージャーを使用して IronPrint をインストールします
このコード スニペットをコピーして実行します。
IronPrint.Printer.Print("document.pdf", new IronPrint.PrintSettings { PaperSize = IronPrint.PaperSize.A4, PaperOrientation = IronPrint.PaperOrientation.Landscape, Dpi = 300, NumberOfCopies = 2, Grayscale = true });実際の環境でテストするためにデプロイする
最小限のワークフロー(5ステップ)
- 印刷設定を構成するための C# ライブラリをダウンロードする
PrintSettingsクラスをインスタンス化します。- 好みに応じて
PrintSettingsオブジェクトを構成する。 - それを
PrintまたはShowPrintDialogメソッドに渡します - 印刷されたPDFドキュメントを確認し、印刷設定が適用されているか確認する
印刷設定はどのようにすればよいですか?
印刷設定を構成するには、PrintSettingsクラスをインスタンス化し、好みに応じて構成します。 PrintまたはShowPrintDialogメソッドでは、2番目のパラメータとしてPrintSettingsオブジェクトを渡します。 以下のコード例はこの使用方法を示しています。 より詳細な例については、印刷設定コード例ページを確認してください。
// 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);なぜ印刷設定を構成する必要があるのですか?
印刷設定とは、ドキュメントまたはコンテンツの印刷方法を指定する構成またはパラメータのセットを指します。 これらの設定には、用紙サイズ、向き(縦または横)、印刷解像度(1インチあたりのドット数 - DPI)、部数、プリンタの選択、余白、グレースケール印刷などのオプションなどの詳細が含まれます。 特定の印刷の好みや要件を達成するために、これらの設定をカスタマイズします。
IronPrintの包括的な印刷設定機能は、開発者に印刷プロセスのあらゆる側面をきめ細かくコントロールすることを提供します。 デスクトップアプリケーションを構築する場合でも、ASP.NET Webアプリケーションを構築する場合でも、適切な設定を行うことで、異なる環境でも一貫した結果を得ることができます。
カスタム印刷設定はいつ使うべきですか?
カスタム印刷設定は、印刷出力を正確に制御する必要がある場合に不可欠です。たとえば、特定の余白を使用してレポートを印刷する場合、複数部のドキュメントを生成する場合、ビジネスニーズに合わせてドキュメントを正しい向きで印刷する場合などです。
ここでは、特定の要件を満たす請求書を印刷するための実用的な例を紹介します:
// Example: Printing invoices with business requirements
using IronPrint;
// Invoice printing with specific business settings
var invoiceSettings = new PrintSettings
{
PaperSize = PaperSize.Letter, // US Letter size for business documents
PaperOrientation = PaperOrientation.Portrait,
Dpi = 600, // High quality for professional output
NumberOfCopies = 3, // Original + customer copy + file copy
PaperMargins = new Margins(15, 15, 15, 25), // Extra bottom margin for footer
Grayscale = false, // Keep company logo in color
PrinterName = "Office Color Printer" // Specific high-quality printer
};
// Print the invoice
Printer.Print("invoice_2024_001.pdf", invoiceSettings);// Example: Printing invoices with business requirements
using IronPrint;
// Invoice printing with specific business settings
var invoiceSettings = new PrintSettings
{
PaperSize = PaperSize.Letter, // US Letter size for business documents
PaperOrientation = PaperOrientation.Portrait,
Dpi = 600, // High quality for professional output
NumberOfCopies = 3, // Original + customer copy + file copy
PaperMargins = new Margins(15, 15, 15, 25), // Extra bottom margin for footer
Grayscale = false, // Keep company logo in color
PrinterName = "Office Color Printer" // Specific high-quality printer
};
// Print the invoice
Printer.Print("invoice_2024_001.pdf", invoiceSettings);印刷設定を指定しないとどうなりますか?
印刷設定が指定されていない場合、IronPrintはシステムのデフォルトプリンターのデフォルト設定を使用します。 システム上で利用可能なプリンタを検出するには、GetPrinterNames メソッドを使用して、接続されているすべてのプリンタをプログラムで取得します。





