C#でPDFドキュメントを印刷する方法

IronPrint を使用した C# ドキュメント印刷チュートリアル

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

IronPrint は、.NET C# 開発者がアプリケーションに印刷機能を統合できるように設計された強力な印刷ライブラリです。 IronPrint は、Windows、macOS、iOS、Android プラットフォームにわたる幅広い互換性を備えており、さまざまなオペレーティング システムで一貫して確実に動作します。 デスクトップ環境、Apple の macOS エコシステム、または iOS や Android などのモバイル プラットフォーム向けのアプリケーションを作成する場合でも、IronPrint は印刷機能の実装を簡素化し、.NET C# 環境でのあらゆる印刷ニーズに対応する多用途でユーザーフレンドリーなソリューションを提供します。

クイックスタート: IronPrint でドキュメントをサイレント印刷する

たった 1 行のコードで印刷できます。ダイアログも煩わしさもありません。 IronPrint.Printer.Print(...)を使用すると、デフォルト設定またはカスタム設定を使用して PDF または画像を直接プリンターに自動的に送信できます。

Nuget Icon今すぐ NuGet で PDF を作成してみましょう:

  1. NuGet パッケージ マネージャーを使用して IronPrint をインストールします

    PM > Install-Package IronPrint

  2. このコード スニペットをコピーして実行します。

    IronPrint.Printer.Print("path/to/your/document.pdf");
  3. 実際の環境でテストするためにデプロイする

    今すぐ無料トライアルでプロジェクトに IronPrint を使い始めましょう
    arrow pointer

目次

-ドキュメントを印刷 -静かに印刷 -ダイアログ付き印刷 -印刷設定を適用する -プリンター情報を取得する -プリンター名を取得する

文書を印刷

静かに印刷

印刷ダイアログを表示せずにドキュメントをシームレスに印刷します。 印刷設定はコード内で直接行うことができます。

// Programmatically print a document without showing the print dialog.
// Define your print job and settings here as needed.

using System;
using IronPrint;

public class SilentPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a silent print job
        var printJob = new PrintJob(document);

        // Apply specific settings as necessary
        // For example: set printer name, copies, etc.

        // Execute the print job
        printJob.PrintSilently();
    }
}
// Programmatically print a document without showing the print dialog.
// Define your print job and settings here as needed.

using System;
using IronPrint;

public class SilentPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a silent print job
        var printJob = new PrintJob(document);

        // Apply specific settings as necessary
        // For example: set printer name, copies, etc.

        // Execute the print job
        printJob.PrintSilently();
    }
}
' Programmatically print a document without showing the print dialog.
' Define your print job and settings here as needed.

Imports System
Imports IronPrint

Public Class SilentPrint
	Public Shared Sub Main()
		' Create a print document instance
		Dim document = New PrintDocument("sample-document.pdf")

		' Initialize a silent print job
		Dim printJob As New PrintJob(document)

		' Apply specific settings as necessary
		' For example: set printer name, copies, etc.

		' Execute the print job
		printJob.PrintSilently()
	End Sub
End Class
$vbLabelText   $csharpLabel

ダイアログ付き印刷

印刷設定ダイアログを表示して印刷処理を開始します。 これにより、ユーザーは印刷オプションをインタラクティブにカスタマイズできます。

// Start a print job with user interaction through the print dialog.

using System;
using IronPrint;

public class DialogPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a print job with dialog
        var printJob = new PrintJob(document);

        // Execute the print job with display of print options dialog
        printJob.PrintWithDialog();
    }
}
// Start a print job with user interaction through the print dialog.

using System;
using IronPrint;

public class DialogPrint
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Initialize a print job with dialog
        var printJob = new PrintJob(document);

        // Execute the print job with display of print options dialog
        printJob.PrintWithDialog();
    }
}
' Start a print job with user interaction through the print dialog.

Imports System
Imports IronPrint

Public Class DialogPrint
	Public Shared Sub Main()
		' Create a print document instance
		Dim document = New PrintDocument("sample-document.pdf")

		' Initialize a print job with dialog
		Dim printJob As New PrintJob(document)

		' Execute the print job with display of print options dialog
		printJob.PrintWithDialog()
	End Sub
End Class
$vbLabelText   $csharpLabel

印刷設定を適用する

特定の要件を満たすようにプログラムで印刷設定を調整します。 このセクションでは、コードを通じて印刷構成を微調整する機能が提供されます。

// Example code to apply custom print settings programmatically.

using System;
using IronPrint;

public class PrintSettingsExample
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Create a print job
        var printJob = new PrintJob(document);

        // Set custom print settings like duplex, color mode, etc.
        var settings = new PrintSettings
        {
            ColorMode = ColorMode.Color,
            DuplexMode = DuplexMode.OneSided,
            Copies = 2
        };

        // Apply settings to print job
        printJob.ApplySettings(settings);

        // Print the document
        printJob.PrintSilently();
    }
}
// Example code to apply custom print settings programmatically.

using System;
using IronPrint;

public class PrintSettingsExample
{
    public static void Main()
    {
        // Create a print document instance
        var document = new PrintDocument("sample-document.pdf");

        // Create a print job
        var printJob = new PrintJob(document);

        // Set custom print settings like duplex, color mode, etc.
        var settings = new PrintSettings
        {
            ColorMode = ColorMode.Color,
            DuplexMode = DuplexMode.OneSided,
            Copies = 2
        };

        // Apply settings to print job
        printJob.ApplySettings(settings);

        // Print the document
        printJob.PrintSilently();
    }
}
' Example code to apply custom print settings programmatically.

Imports System
Imports IronPrint

Public Class PrintSettingsExample
	Public Shared Sub Main()
		' Create a print document instance
		Dim document = New PrintDocument("sample-document.pdf")

		' Create a print job
		Dim printJob As New PrintJob(document)

		' Set custom print settings like duplex, color mode, etc.
		Dim settings = New PrintSettings With {
			.ColorMode = ColorMode.Color,
			.DuplexMode = DuplexMode.OneSided,
			.Copies = 2
		}

		' Apply settings to print job
		printJob.ApplySettings(settings)

		' Print the document
		printJob.PrintSilently()
	End Sub
End Class
$vbLabelText   $csharpLabel

プリンター情報を取得する

プリンター名を取得する

利用可能なすべてのプリンターのリストにアクセスします。 情報提供の目的やアプリケーションでの動的なプリンター選択のために、システムにインストールされているプリンターの名前を取得します。

// Retrieve and display a list of printer names available on the system.

using System;
using IronPrint;

public class PrinterInfo
{
    public static void Main()
    {
        // Get an enumerable list of printer names
        var printerNames = PrinterSettings.GetAvailablePrinters();

        // Print each printer name to the console
        Console.WriteLine("Available Printers:");
        foreach (var name in printerNames)
        {
            Console.WriteLine(name);
        }
    }
}
// Retrieve and display a list of printer names available on the system.

using System;
using IronPrint;

public class PrinterInfo
{
    public static void Main()
    {
        // Get an enumerable list of printer names
        var printerNames = PrinterSettings.GetAvailablePrinters();

        // Print each printer name to the console
        Console.WriteLine("Available Printers:");
        foreach (var name in printerNames)
        {
            Console.WriteLine(name);
        }
    }
}
' Retrieve and display a list of printer names available on the system.

Imports System
Imports IronPrint

Public Class PrinterInfo
	Public Shared Sub Main()
		' Get an enumerable list of printer names
		Dim printerNames = PrinterSettings.GetAvailablePrinters()

		' Print each printer name to the console
		Console.WriteLine("Available Printers:")
		For Each name In printerNames
			Console.WriteLine(name)
		Next name
	End Sub
End Class
$vbLabelText   $csharpLabel

よくある質問

どのようにして .NET C# でドキュメントを静かに印刷できますか?

PrintJob インスタンスの PrintSilently() メソッドを使用して、ユーザーの操作なしで印刷ジョブを実行可能。これにより、印刷ダイアログを表示せずにプログラムでドキュメントが印刷可能。

どのように .NET C# で印刷ダイアログを使用してドキュメントを印刷できますか?

PrintJob インスタンスの PrintWithDialog() メソッドを使用してユーザー操作で印刷ジョブを開始可能。これにより、印刷設定ダイアログが表示され、印刷前にユーザーがオプションをカスタマイズ可能。

.NET C# でプログラム的にカスタム印刷設定を適用することはできますか?

PrintSettings オブジェクトを作成し、カラーモード、両面印刷モード、コピー数などのプロパティを設定することで、プログラムでカスタム印刷設定を適用可能。その後、これらの設定を PrintJob インスタンスに適用できます。

.NET C#アプリケーションで利用可能なプリンタ名を取得するにはどうすればよいですか?

PrinterSettings.GetAvailablePrinters() メソッドを使用して利用可能なプリンター名を取得できます。これにより、選択や情報提供のために、システムにインストールされたプリンター名の列挙可能リストが得られます。

.NET C# ライブラリを使用してさまざまなドキュメント形式を印刷することができますか?

はい、このライブラリは PDF、PNG、HTML、TIFF、GIF、JPEG、IMAGE、および BITMAP などのさまざまなドキュメント形式の印刷をサポートしており、多様なドキュメント印刷オプションが可能。

.NET C# ライブラリを使用してドキュメントを印刷するためにサポートされているプラットフォームは何ですか?

このライブラリは Windows、macOS、iOS、Android などの複数のプラットフォームをサポートしており、これらのオペレーティングシステム全体で一貫して信頼性のある印刷機能を提供。

.NET C# における無音印刷はダイアログベースの印刷とどのように異なりますか?

無音印刷は PrintSilently() メソッドを使用して、ユーザーの操作なしにプログラムで印刷を可能にします。ダイアログベースの印刷では、PrintWithDialog() メソッドを介して印刷ダイアログを表示し、ユーザーがカスタマイズすることができます。

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

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

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

準備はできましたか?
Nuget ダウンロード 34,704 | Version: 2025.11 リリース