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

Print Document Tutorial

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

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

クイックスタート: IronPrintを使用してドキュメントを静かに印刷する

コード一行だけで印刷できます—ダイアログなし、手間なし。 IronPrint.Printer.Print(...)を使用して、デフォルトまたはカスタム設定を用いてPDFや画像をプリンタに直接静かに送信します。

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("path/to/your/document.pdf");
  3. Deploy to test on your live environment

    Start using IronPrint in your project today with a free trial
    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
テクニカルライター

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

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

準備はいいですか?
Nuget ダウンロード 34,016 | バージョン: 2025.11 ただ今リリースされました