フッターコンテンツにスキップ
IRONPRINTの使用

C#でPDFファイルをサイレント印刷する方法

role="alert"> IronPrintはIron Softwareの新しい.NET印刷ライブラリであり、Windows、macOS、Android、iOSを含む幅広いプラットフォームでの互換性を提供します。IronPrintを始めましょう

PDFドキュメントは、要求されたフォーマットでデータを保存および転送できるポータブルドキュメント形式です。 それは保存されたデータのフォーマットを維持し、ユーザーがデジタルドキュメントを扱う他の側面に集中することを可能にします。 デジタルドキュメントを印刷することは、プラットフォームによってデータの表示が異なるため、手間のかかる作業です。 しかし、PDFドキュメントでデータを送信することで、印刷のためのフォーマットを維持するのに役立ちます。 しかし、C#の開発者にとってプログラムでPDFファイルを印刷することは課題となる可能性があります。 IronPDF - C# PDF Libraryのおかげで、PDFファイルの印刷プロセスが非常に簡単で手間のかからないものになります。

この記事では、IronPDFライブラリを使用してC#でPDFドキュメントを静かに印刷する方法を説明します。

class="hsg-featured-snippet">

How to Print PDF File Silently in C#

  1. PDFファイルを静かに印刷するためのC#ライブラリをインストールする
  2. Printメソッドを使用してPDFドキュメントをデフォルト設定で印刷する
  3. 特定のプリンターをターゲットにするためにPrinterNameプロパティを設定する
  4. C#でPrinterResolutionクラスを使用してカスタム解像度を設定する
  5. プリンターダイアログを開かずに指定されたディレクトリにPDFを静かに印刷する

IronPDF - C# PDF Library

IronPDFはC# .NETライブラリです、開発者がPDFドキュメントを作成、読み取り、編集することを可能にします。 これは一流のC#ライブラリであり、正確さ、使いやすさ、および速度を優先します。 それは特にC#, F#, & VB.NET用に設計されており、.NET 7, 6, 5, Core, Standard, or Framework.と高い互換性を持ち、IronPDFの強力なChromiumエンジンを活用してWeb、デスクトップ、およびコンソールからHTMLからPDFを生成するのに役立ちます。

さらに、IronPDFはユーザーにPDFを操作および編集する機能を提供し、ヘッダーやフッターを追加し、PDFからテキストや画像を簡単に抽出します。

いくつかの重要な特徴には次のものがあります:

  • さまざまなファイル形式からPDFファイルを読み込み生成する
  • デフォルトのプリンターを使用してPDFファイルを保存および印刷する
  • PDFファイルのマージと分割
  • Adobe Readerを使わないPDFエディター

Steps to Silently Print PDF Documents in C# using IronPDF Library

PDFドキュメントを静かに印刷するには、まずローカルコンピューターに次のコンポーネントをインストールする必要があります。

  1. Visual Studio - これはC#開発の公式IDEであり、コンピューターにインストールする必要があります。 Visual Studioのウェブサイトからダウンロードとインストールが可能です。
  2. プロジェクトの作成 - C#でのPDF印刷用のコンソールアプリケーションを作成するには、Visual Studio 2022を使用して次の手順に従います。

    • Visual Studioを開き、新しいプロジェクトを作成をクリックしてください

      class="content-img-align-center"> Visual Studio

      class="content__image-caption">Visual Studio

    • C#コンソールアプリを選択し、「次へ」をクリックします

      class="content-img-align-center"> New Project Dialog Box

      class="content__image-caption">新しいプロジェクトダイアログボックス

    • プロジェクトの名前を入力し、場所を選択し、「次へ」をクリックします

      class="content-img-align-center"> Web Forms

      class="content__image-caption">Webフォーム

    • アプリケーションのために最新の.NET Frameworkを選択します。 安定版のバージョン6.0を使用します。

      class="content-img-align-center"> Additional Information

      class="content__image-caption">追加情報

    • 「作成」をクリックすると、コンソールプロジェクトが作成され、プログラムでPDFドキュメントを印刷する準備が整いました。
  3. IronPDFのインストール - IronPDFライブラリをダウンロードしてインストールするための3つの方法があります。 それらは次の通りです:

    • Visual Studioを使用 - Visual Studioには、C#プロジェクトにNuGetパッケージをインストールするのに役立つNuGetパッケージマネージャーがあります。

      • メニューバーの「ツール」をクリックするか、
      • ソリューションエクスプローラーでプロジェクトファイルを右クリック

        class="content-img-align-center"> Solution Explorer

        class="content__image-caption">ソリューションエクスプローラー

        class="content-img-align-center">  related to Steps to Silently Print PDF Documents in C# using IronPDF Library

        class="content__image-caption">プロジェクトメニュー > NuGetパッケージの管理

      • 開始したら、NuGetパッケージマネージャーでIronPDFを検索し、以下のようにインストールします:

        class="content-img-align-center"> Install IronPDF from NuGet Package

        class="content__image-caption">NuGetパッケージからIronPDFをインストール

    • NuGetパッケージを直接ダウンロード - IronPDFをダウンロードする別の方法は、NuGetウェブサイトにアクセスしてパッケージを直接ダウンロードすることです。 こちらがリンクhttps://www.nuget.org/packages/IronPdf/です。
    • IronPDF .DLLライブラリをダウンロード - IronPDFはIronPDFウェブサイトからも直接ダウンロードできます。Navigate to: IronPDF DLLダウンロードでインストールします。 プロジェクトで.DLLファイルを参照して使用します。

PDFファイルと印刷ジョブを生成

ここでは、URLからPDFファイルを生成します。 PDFファイルの作成は簡単で、多くの場合2段階のプロセスです。 以下のコードサンプルはPDFを生成します:

using IronPdf;

// Initialize a new instance of ChromePdfRenderer.
ChromePdfRenderer Renderer = new ChromePdfRenderer();

// Render the specified URL as a PDF document.
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
using IronPdf;

// Initialize a new instance of ChromePdfRenderer.
ChromePdfRenderer Renderer = new ChromePdfRenderer();

// Render the specified URL as a PDF document.
PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Imports IronPdf

' Initialize a new instance of ChromePdfRenderer.
Private Renderer As New ChromePdfRenderer()

' Render the specified URL as a PDF document.
Private Pdf As PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
$vbLabelText   $csharpLabel

上記のコードでPDFドキュメントオブジェクトが作成され、印刷の準備が整いました。 次にデフォルトのプリンターを使用して紙にPDFを印刷ドキュメントを行います。 コードはワンライナーであり、次のようになります:

// Print the PDF document using the default printer settings.
Pdf.Print();
// Print the PDF document using the default printer settings.
Pdf.Print();
' Print the PDF document using the default printer settings.
Pdf.Print()
$vbLabelText   $csharpLabel

このPrintメソッドは印刷のためにPDFをデフォルトプリンターに送信します。

高度な印刷オプション

静かな印刷 のために IronPDF は様々な高度な印刷オプションを提供します。

PdfDocument.GetPrintDocument メソッドが使用され、その結果は System.Drawing.Printing.PrintDocument オブジェクトに格納されます。 コードはシンプルで次のようになります:

// Remember to add assembly reference to System.Drawing.dll in project

// Get the print document for the PDF.
System.Drawing.Printing.PrintDocument PrintPDF = Pdf.GetPrintDocument();
// Remember to add assembly reference to System.Drawing.dll in project

// Get the print document for the PDF.
System.Drawing.Printing.PrintDocument PrintPDF = Pdf.GetPrintDocument();
' Remember to add assembly reference to System.Drawing.dll in project

' Get the print document for the PDF.
Dim PrintPDF As System.Drawing.Printing.PrintDocument = Pdf.GetPrintDocument()
$vbLabelText   $csharpLabel

プリンター名の指定

IronPDFは、特定のプリンターに印刷する機会も提供します。 名前を指定するには、 PrinterSettings.PrinterName プロパティが使用されます。 まず、現在のPDFドキュメントオブジェクトを取得する必要があります。 コードサンプルは次のようになります:

using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Send the print job to the specified printer.
    printDocument.Print();
}
using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Send the print job to the specified printer.
    printDocument.Print();
}
Using printDocument = pdfDocument.GetPrintDocument()
	' Specify the printer name.
	printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF"

	' Send the print job to the specified printer.
	printDocument.Print()
End Using
$vbLabelText   $csharpLabel

プリンターの解像度を設定

別のクールな機能は、プリンターの解像度の設定です。 表示、印刷するピクセル数を制御できます。 PDFドキュメントのDefaultPageSettings.PrinterResolutionプロパティを使用して解像度を設定できます。 非常に迅速なコードサンプルを以下に示します:

// Set the custom resolution for the printer.
printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
{
    Kind = PrinterResolutionKind.Custom,
    X = 1200,
    Y = 1200
};

// Send the print job with the custom resolution settings.
printDocument.Print();
// Set the custom resolution for the printer.
printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
{
    Kind = PrinterResolutionKind.Custom,
    X = 1200,
    Y = 1200
};

// Send the print job with the custom resolution settings.
printDocument.Print();
' Set the custom resolution for the printer.
printDocument.DefaultPageSettings.PrinterResolution = New PrinterResolution With {
	.Kind = PrinterResolutionKind.Custom,
	.X = 1200,
	.Y = 1200
}

' Send the print job with the custom resolution settings.
printDocument.Print()
$vbLabelText   $csharpLabel

PrintToFileメソッド

PdfDocumentクラスは、 PDFをファイルに印刷 するC#のPrintToFileメソッドを提供します。 このメソッドは、ファイルを直接その場所に印刷するためにpathToFileを引数とし、プリンターダイアログを開くことなくファイルを印刷できます。 コードは簡単で次の通りです:

// Print the document to a specified file location.
printDocument.PrintToFile("PathToFile", false);
// Print the document to a specified file location.
printDocument.PrintToFile("PathToFile", false);
' Print the document to a specified file location.
printDocument.PrintToFile("PathToFile", False)
$vbLabelText   $csharpLabel

完全なコード例は次の通りです:

using IronPdf;

// Initialize the PDF renderer and create the PDF document.
ChromePdfRenderer Renderer = new ChromePdfRenderer();
PdfDocument pdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Set a custom print resolution.
    printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
    {
        Kind = PrinterResolutionKind.Custom,
        X = 1200,
        Y = 1200
    };

    // Execute the print job.
    printDocument.Print();
}
using IronPdf;

// Initialize the PDF renderer and create the PDF document.
ChromePdfRenderer Renderer = new ChromePdfRenderer();
PdfDocument pdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/");

using (var printDocument = pdfDocument.GetPrintDocument())
{
    // Specify the printer name.
    printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF";

    // Set a custom print resolution.
    printDocument.DefaultPageSettings.PrinterResolution = new PrinterResolution
    {
        Kind = PrinterResolutionKind.Custom,
        X = 1200,
        Y = 1200
    };

    // Execute the print job.
    printDocument.Print();
}
Imports IronPdf

' Initialize the PDF renderer and create the PDF document.
Private Renderer As New ChromePdfRenderer()
Private pdfDocument As PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/")

Using printDocument = pdfDocument.GetPrintDocument()
	' Specify the printer name.
	printDocument.PrinterSettings.PrinterName = "Microsoft Print to PDF"

	' Set a custom print resolution.
	printDocument.DefaultPageSettings.PrinterResolution = New PrinterResolution With {
		.Kind = PrinterResolutionKind.Custom,
		.X = 1200,
		.Y = 1200
	}

	' Execute the print job.
	printDocument.Print()
End Using
$vbLabelText   $csharpLabel

コードを実行すると、それがURLをPDFドキュメントに変換します。 次に、PDFドキュメントを静かに印刷するために、GetPrintDocumentメソッドが使用されます。 プログラムファイルを正常にコンパイルし、実行すると、PDFドキュメントとして保存するためのプリンターダイアログボックスが表示されます。 指定されたプリンター名を使用してPDFが保存されます。

class="content-img-align-center"> Csharp Print Pdf Silently 8 related to PrintToFileメソッド

class="content__image-caption">

class="content-img-align-center"> Csharp Print Pdf Silently 9 related to PrintToFileメソッド

class="content__image-caption">

まとめ

この記事では、IronPDFを使用してPDFドキュメントを静かに印刷する方法を詳しく見てきました。 IronPDFは、PDF印刷時に多くの便利なオプションを提供します。 また、印刷されたページを追跡したり、ページ範囲内での印刷も可能です。

静かな印刷を含むその他の印刷オプションにより、IronPDFはPDFを扱う際のC#内での優れたライブラリになります。

IronPDFはさまざまな形式からPDFに、そしてPDFからさまざまな形式へのデータの変換を助けます。 開発者がアプリケーション開発プロセスにPDF機能を統合しやすくします。 さらに、Adobe Acrobat Readerを使用せずにPDFドキュメントを表示および編集することができます。

IronPDFは個人開発のために無料で提供され、商用使用のためにライセンス供与されます。 It provides a free trial license to access and test out the full functionality of the library. 詳細についてはこのリンクをチェックしてください。

よくある質問

C#でPDFを静かに印刷するにはどうすればいいですか?

IronPDFのPrintメソッドを使用することで、C#でPDFを静かに印刷できます。これによりプリンターダイアログを開かずに印刷でき、ドキュメントのフォーマットが保持されます。

静かにPDFを印刷するためにIronPDFを設定するにはどのような手順が必要ですか?

静かにPDFを印刷するためにIronPDFを設定するには、NuGetパッケージマネージャーを介してライブラリをインストールするか、.DLLファイルをダウンロードします。次に、Printメソッドを使用して静かな印刷設定を構成し、PrinterNamePrinterResolutionのようなプリンターのプロパティを指定してください。

印刷時にPDFのフォーマットを保持するにはどうすればよいですか?

IronPDFは、特定のプリンター設定を構成することができ、PrinterResolutionプロパティの設定などにより、印刷の出力が元のドキュメントと一致することを保証します。

C#でPDFをファイルの場所に印刷できますか?

はい、IronPDFはPrintToFileメソッドを提供しており、プリンターダイアログを開かずに指定されたファイルの場所にPDFを直接印刷できます。

Adobe Acrobat Readerを使用せずにPDFを印刷できますか?

はい、IronPDFは、Adobe Acrobat Readerを必要とせずにPDFを印刷、表示、編集することができ、C#アプリケーションでPDFドキュメントを扱うための柔軟なツールです。

IronPDFはクロスプラットフォームのPDF印刷をサポートしていますか?

はい、IronPDFはクロスプラットフォームのPDF印刷をサポートしており、Windows、macOS、Android、iOSなどに対応しているため、さまざまな開発環境での利用が可能です。

IronPDFの試用オプションにはどのようなものがありますか?

IronPDFは個人開発用に無料で提供されており、商用ライセンスを取得する前にその全機能をテストできる試用ライセンスがあります。

IronPDFを使用してPDF印刷のための特定のプリンターを指定するにはどうすればよいですか?

IronPDFでPrinterSettings.PrinterNameプロパティを設定することで、特定のプリンターを指定し、プリントジョブを希望のプリンターに振り向けることができます。

C#アプリケーションをIronPDFで開発するために推奨されるIDEは何ですか?

Visual Studioは、IronPDFを使用したC#アプリケーションの開発に推奨される統合開発環境(IDE)であり、コーディングとプロジェクト管理のための堅牢なプラットフォームを提供します。

C#での静かなPDF印刷に関する問題をどのようにトラブルシュートできますか?

C#での静かなPDF印刷に問題が発生した場合、IronPDFが正しくインストールされていること、PrinterNamePrinterResolutionなどのプリンター設定が正確に構成されていることを確認してください。IronPDFのドキュメントを参照することも、役立つトラブルシューティングのヒントを提供するかもしれません。

Curtis Chau
テクニカルライター

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

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