IronPrintによるC#ドキュメント印刷チュートリアル
IronPrint は、.NET C# 開発者がアプリケーションに印刷機能を統合できるように設計された強力な印刷ライブラリです。 IronPrint は、Windows、macOS、iOS、Android プラットフォームにわたる幅広い互換性を備えており、さまざまなオペレーティング システムで一貫して確実に動作します。 デスクトップ環境、Apple の macOS エコシステム、または iOS や Android などのモバイル プラットフォーム向けのアプリケーションを作成する場合でも、IronPrint は印刷機能の実装を簡素化し、.NET C# 環境でのあらゆる印刷ニーズに対応する多用途でユーザーフレンドリーなソリューションを提供します。
クイックスタート: IronPrintでドキュメントをサイレントに印刷するわずか1行のコードで印刷完了 - ダイアログ不要、面倒なし。 IronPrint.Printer.Print(...) を使用して、PDFや画像をデフォルト設定またはカスタム設定でプリンタにすぐ送信します。
-
1IronPrint を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
IronPrint.Printer.Print("path/to/your/document.pdf");IronPrint.Printer.Print("path/to/your/document.pdf")IronPrint.Printer.Print("path/to/your/document.pdf") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronPrintを使い始めるには、無料トライアルをお試しください。
目次
文書を印刷
静かに印刷
印刷ダイアログを表示せずにドキュメントを印刷します。 印刷設定はコード内で直接行うことができます。
// 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()
{
// Apply specific settings as necessary
// For example: set printer name, copies, etc.
var settings = new PrintSettings();
// Print the document without displaying the print dialog
Printer.Print("sample-document.pdf", settings);
}
}// 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()
{
// Apply specific settings as necessary
// For example: set printer name, copies, etc.
var settings = new PrintSettings();
// Print the document without displaying the print dialog
Printer.Print("sample-document.pdf", settings);
}
}Imports System
Imports IronPrint
Public Class SilentPrint
Public Shared Sub Main()
' Apply specific settings as necessary
' For example: set printer name, copies, etc.
Dim settings = New PrintSettings()
' Print the document without displaying the print dialog
Printer.Print("sample-document.pdf", settings)
End Sub
End ClassImports System
Imports IronPrint
Public Class SilentPrint
Public Shared Sub Main()
' Apply specific settings as necessary
' For example: set printer name, copies, etc.
Dim settings = New PrintSettings()
' Print the document without displaying the print dialog
Printer.Print("sample-document.pdf", settings)
End Sub
End Classダイアログ付き印刷
印刷設定ダイアログを表示して印刷処理を開始します。 これにより、ユーザーは印刷オプションをインタラクティブにカスタマイズできます。
// Start a print job with user interaction through the print dialog.
using System;
using IronPrint;
public class DialogPrint
{
public static void Main()
{
var settings = new PrintSettings();
// Show the print dialog so the user can customize print options
Printer.ShowPrintDialog("sample-document.pdf", settings);
}
}// Start a print job with user interaction through the print dialog.
using System;
using IronPrint;
public class DialogPrint
{
public static void Main()
{
var settings = new PrintSettings();
// Show the print dialog so the user can customize print options
Printer.ShowPrintDialog("sample-document.pdf", settings);
}
}Imports System
Imports IronPrint
Public Class DialogPrint
Public Shared Sub Main()
Dim settings = New PrintSettings()
' Show the print dialog so the user can customize print options
Printer.ShowPrintDialog("sample-document.pdf", settings)
End Sub
End ClassImports System
Imports IronPrint
Public Class DialogPrint
Public Shared Sub Main()
Dim settings = New PrintSettings()
' Show the print dialog so the user can customize print options
Printer.ShowPrintDialog("sample-document.pdf", settings)
End Sub
End Class印刷設定を適用する
特定の要件を満たすようにプログラムで印刷設定を調整します。 このセクションでは、コードを通じて印刷構成を微調整する機能が提供されます。
// Example code to apply custom print settings programmatically.
using System;
using IronPrint;
public class PrintSettingsExample
{
public static void Main()
{
// Set custom print settings such as grayscale and number of copies
var settings = new PrintSettings
{
Grayscale = false,
NumberOfCopies = 2
};
// Print the document using the configured settings
Printer.Print("sample-document.pdf", settings);
}
}// Example code to apply custom print settings programmatically.
using System;
using IronPrint;
public class PrintSettingsExample
{
public static void Main()
{
// Set custom print settings such as grayscale and number of copies
var settings = new PrintSettings
{
Grayscale = false,
NumberOfCopies = 2
};
// Print the document using the configured settings
Printer.Print("sample-document.pdf", settings);
}
}Imports System
Imports IronPrint
Public Class PrintSettingsExample
Public Shared Sub Main()
' Set custom print settings such as grayscale and number of copies
Dim settings = New PrintSettings With {
.Grayscale = False,
.NumberOfCopies = 2
}
' Print the document using the configured settings
Printer.Print("sample-document.pdf", settings)
End Sub
End ClassImports System
Imports IronPrint
Public Class PrintSettingsExample
Public Shared Sub Main()
' Set custom print settings such as grayscale and number of copies
Dim settings = New PrintSettings With {
.Grayscale = False,
.NumberOfCopies = 2
}
' Print the document using the configured settings
Printer.Print("sample-document.pdf", settings)
End Sub
End Classプリンター情報を取得する
プリンター名を取得する
利用可能なすべてのプリンターのリストにアクセスします。 情報提供の目的やアプリケーションでの動的なプリンター選択のために、システムにインストールされているプリンターの名前を取得します。
// 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 = Printer.GetPrinterNames();
// 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 = Printer.GetPrinterNames();
// Print each printer name to the console
Console.WriteLine("Available Printers:");
foreach (var name in printerNames)
{
Console.WriteLine(name);
}
}
}Imports System
Imports IronPrint
Public Class PrinterInfo
Public Shared Sub Main()
' Get an enumerable list of printer names
Dim printerNames = Printer.GetPrinterNames()
' Print each printer name to the console
Console.WriteLine("Available Printers:")
For Each name In printerNames
Console.WriteLine(name)
Next
End Sub
End ClassImports System
Imports IronPrint
Public Class PrinterInfo
Public Shared Sub Main()
' Get an enumerable list of printer names
Dim printerNames = Printer.GetPrinterNames()
' Print each printer name to the console
Console.WriteLine("Available Printers:")
For Each name In printerNames
Console.WriteLine(name)
Next
End Sub
End Classよくある質問
IronPrintはどのプラットフォームでドキュメント印刷をサポートしていますか?
IronPrintはWindows、macOS、iOS、Androidを含む幅広いプラットフォームでの印刷をサポートし、多様なオペレーティングシステムでの統合を簡単にしています。
IronPrintを使用して印刷ダイアログを表示せずにドキュメントを印刷するにはどうすればよいですか?
IronPrintを使用すると、次のように一行のコードでドキュメントを静かに印刷できます: IronPrint.Printer.Print("path/to/your/document.pdf");。これにより、PDFをダイアログなしで直接プリンターに送信できます。
IronPrintを使用してプログラムで印刷設定をカスタマイズできますか?
はい、IronPrintを用いて、プリンター名、コピー数などをC#アプリケーションコード内で定義することにより、プログラムで印刷設定をカスタマイズできます。
IronPrintを使用して対話的に印刷オプションを設定することは可能ですか?
IronPrintは印刷ダイアログを利用してユーザーの好みに応じた様々な印刷設定をカスタマイズするための対話的なオプションで印刷ジョブを始めることができます。
IronPrintを使用して利用可能なプリンターの名前を取得する方法は?
Printer.GetPrinterNames() メソッドを実装することで、システムにインストールされているプリンター名のリストをIronPrintを通じて取得できます。
IronPrintが対応できるドキュメントタイプの例は何ですか?
IronPrintはPDF、PNG、HTML、TIFF、GIF、JPEGなどの複数のドキュメントタイプを処理でき、様々な印刷ニーズに応える多用途なツールです。
IronPrintはデスクトップおよびモバイルアプリケーションの両方で互換性がありますか?
はい、IronPrintはデスクトップ環境(WindowsとmacOS)およびモバイルプラットフォーム(iOSとAndroid)の両方で互換性があり、様々なデバイスで柔軟な印刷ソリューションを提供します。
IronPrintはグレースケール印刷を行い、コピー数をプログラムで調整できますか?
はい、IronPrintの PrintSettings クラスを使用して、グレースケールの有効化やコピー数の指定などのカスタム印刷設定をC#コード内で直接行えます。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。