C言語でWord文書を印刷する方法
C#でWord文書を印刷するには、 IronWordを使用して文書を作成し、 IronPDFを使用してPDF形式に変換し、 IronPrintを使用して複数のプラットフォームでカスタマイズ可能な設定で印刷処理を行います。
C#アプリケーションを開発する際、プログラムによってWord文書を生成・印刷する必要が生じる場面がよくあります。 レポート作成、文書処理、Professional成果物の作成など、どのような作業を行う場合でも、信頼できるツールがあれば大きな違いが生まれます。 そこで登場するのが、Iron Software社のIronWord 、 IronPDF 、 IronPrintです。これらのライブラリは連携して動作し、C#アプリケーションにおけるドキュメントの作成、変換、印刷を簡素化します。
この記事では、 IronPrintを使った印刷方法、 IronWordを使ったWord文書の作成方法、そしてIronPDFを使ったPDFへの変換方法について説明します。 Enterprise向けレポートシステムを構築する場合でも、文書ワークフローを自動化する場合でも、これらのツールは文書処理に必要なすべてを提供します。
C# で Word 文書を印刷する方法
- Visual Studioプロジェクトを作成
- IronWord、IronPDF、IronPrintライブラリをインストールする
- IronWordを使用してWord文書を作成します。
SaveAsメソッドを使用して Word 文書を保存します。- IronPDFの
DocxToPdfRendererメソッドを使用してPDFドキュメントを作成します。 - IronPrintを使用して
PrinterSettingsを調整します - IronPrint
Printer.Printメソッドを使用して印刷します
IronPrintとは何ですか?
IronPrintは、 .NET向けの効率的な印刷ライブラリであり、C#で印刷を完全に制御できます。 Iron Software社が開発したこのツールは、印刷作業専用に設計されたクラスとメソッドを提供し、印刷プロセスのあらゆる側面を細かく調整できます。 このライブラリは.NET Frameworkと.NET Coreの両方でスムーズに動作するため、あらゆる種類のアプリケーションで使用できます。
IronPrintの主な機能は何ですか?
IronPrintは印刷設定をどのように処理しますか?
IronPrintを使えば、印刷ジョブのあらゆる側面をカスタマイズできます。
用紙サイズ(レター、リーガル、A4、A3、カスタム)
- 向き(縦向きまたは横向き)
- 品質管理のためのDPI
- 丁合部数
- プリンターの選定と検証
- 正確な寸法の余白
- コスト削減のためのグレースケール印刷
// Example: Advanced print settings configuration
using IronPrint;
// Create complete print settings
PrintSettings advancedSettings = new PrintSettings()
{
PrinterName = "HP LaserJet Pro",
PaperSize = PaperSize.A4,
PrintOrientation = PrintOrientation.Portrait,
Dpi = 600, // High quality print
NumberOfCopies = 3,
Grayscale = true,
PaperMargins = new Margins(50, 50, 40, 40) // Left, Right, Top, Bottom
};
// Apply settings to print job
Printer.Print("document.pdf", advancedSettings);
// Example: Advanced print settings configuration
using IronPrint;
// Create complete print settings
PrintSettings advancedSettings = new PrintSettings()
{
PrinterName = "HP LaserJet Pro",
PaperSize = PaperSize.A4,
PrintOrientation = PrintOrientation.Portrait,
Dpi = 600, // High quality print
NumberOfCopies = 3,
Grayscale = true,
PaperMargins = new Margins(50, 50, 40, 40) // Left, Right, Top, Bottom
};
// Apply settings to print job
Printer.Print("document.pdf", advancedSettings);
Imports IronPrint
' Example: Advanced print settings configuration
' Create complete print settings
Dim advancedSettings As New PrintSettings() With {
.PrinterName = "HP LaserJet Pro",
.PaperSize = PaperSize.A4,
.PrintOrientation = PrintOrientation.Portrait,
.Dpi = 600, ' High quality print
.NumberOfCopies = 3,
.Grayscale = True,
.PaperMargins = New Margins(50, 50, 40, 40) ' Left, Right, Top, Bottom
}
' Apply settings to print job
Printer.Print("document.pdf", advancedSettings)
プリンタクラスはどのように動作するのですか?
Printer クラスはIronPrintの中核です。 画像やPDFなど、さまざまなファイル形式を印刷するための機能を提供します。 あらゆる印刷シナリオに統合でき、リアルタイムアプリケーション向けの印刷ダイアログもサポートしています。 ShowPrintDialog メソッドは、ユーザーが必要なときに使い慣れた印刷設定オプションを提供します。
IronPrintはどのプラットフォームをサポートしていますか?
IronPrintはWindows、macOS、Android、iOSに対応しており、どこに展開しても一貫した印刷機能を提供します。 このクロスプラットフォームサポートは、WPF、Windows Forms、およびASP.NETアプリケーションにも適用されます。
必要な前提条件は何ですか?
始める前に、以下のものを用意してください。
Word文書の作成、変換、印刷方法を教えてください
それでは、Word文書を作成し、それをPDFに変換し、3つのライブラリすべてを使用して印刷するC#コンソールアプリケーションを作成してみましょう。
ステップ1: Visual StudioでC#コンソールアプリケーションを作成する
- Visual Studioを開き、新しいC#コンソールアプリケーションを作成します。
- プロジェクトを設定し、"次へ"をクリックします。
- "追加情報"から.NET Frameworkを選択し、"作成"をクリックします。
ステップ2: NuGetパッケージマネージャーを使用して必要なライブラリをインストールする
- [ツール] メニューからNuGetパッケージ マネージャー コンソールを開きます。
- [参照]タブで各ライブラリを検索し、[インストール]をクリックします。
-
以下のコマンドを使用してIronPrintをインストールします。
Install-Package IronPrint
-
IronWordとIronPDFを同じ方法でインストールします。 コンソールでは、以下を使用してください。
Install-Package IronWord Install-Package IronPdfInstall-Package IronWord Install-Package IronPdfSHELL
ステップ3: IronWordを使用してWord文書を作成する
まずはIronWordを使って簡単なWord文書を作成してみましょう。
using IronWord;
using IronWord.Models;
// Code to Create Word File
// Create a TextRun object with sample text
TextRun textRun = new TextRun("Sample text");
// Create a paragraph and add the TextRun to it
Paragraph paragraph = new Paragraph();
paragraph.AddTextRun(textRun);
// Create a Word document object with the paragraph and save it as a .docx file
WordDocument doc = new WordDocument(paragraph);
doc.SaveAs("assets/document.docx");
using IronWord;
using IronWord.Models;
// Code to Create Word File
// Create a TextRun object with sample text
TextRun textRun = new TextRun("Sample text");
// Create a paragraph and add the TextRun to it
Paragraph paragraph = new Paragraph();
paragraph.AddTextRun(textRun);
// Create a Word document object with the paragraph and save it as a .docx file
WordDocument doc = new WordDocument(paragraph);
doc.SaveAs("assets/document.docx");
Imports IronWord
Imports IronWord.Models
' Code to Create Word File
' Create a TextRun object with sample text
Private textRun As New TextRun("Sample text")
' Create a paragraph and add the TextRun to it
Private paragraph As New Paragraph()
paragraph.AddTextRun(textRun)
' Create a Word document object with the paragraph and save it as a .docx file
Dim doc As New WordDocument(paragraph)
doc.SaveAs("assets/document.docx")
現状は以下の通りです。
- テキストを使用して
TextRunを作成します。 Paragraphに追加してくださいWordDocumentを作成して保存します
より複雑な文書の場合は、書式設定、複数の段落、表を追加します。
using IronWord;
using IronWord.Models;
// Create a more complex Word document
WordDocument complexDoc = new WordDocument();
// Add a title paragraph with formatting
TextRun titleRun = new TextRun("Quarterly Sales Report")
{
FontSize = 24,
Bold = true,
FontFamily = "Arial"
};
Paragraph titleParagraph = new Paragraph();
titleParagraph.AddTextRun(titleRun);
// Add body content
TextRun bodyRun = new TextRun("This report contains sales data for Q4 2023.");
Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddTextRun(bodyRun);
// Add paragraphs to document
complexDoc.AddParagraph(titleParagraph);
complexDoc.AddParagraph(bodyParagraph);
// Save the document
complexDoc.SaveAs("assets/sales_report.docx");
using IronWord;
using IronWord.Models;
// Create a more complex Word document
WordDocument complexDoc = new WordDocument();
// Add a title paragraph with formatting
TextRun titleRun = new TextRun("Quarterly Sales Report")
{
FontSize = 24,
Bold = true,
FontFamily = "Arial"
};
Paragraph titleParagraph = new Paragraph();
titleParagraph.AddTextRun(titleRun);
// Add body content
TextRun bodyRun = new TextRun("This report contains sales data for Q4 2023.");
Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddTextRun(bodyRun);
// Add paragraphs to document
complexDoc.AddParagraph(titleParagraph);
complexDoc.AddParagraph(bodyParagraph);
// Save the document
complexDoc.SaveAs("assets/sales_report.docx");
Imports IronWord
Imports IronWord.Models
' Create a more complex Word document
Dim complexDoc As New WordDocument()
' Add a title paragraph with formatting
Dim titleRun As New TextRun("Quarterly Sales Report") With {
.FontSize = 24,
.Bold = True,
.FontFamily = "Arial"
}
Dim titleParagraph As New Paragraph()
titleParagraph.AddTextRun(titleRun)
' Add body content
Dim bodyRun As New TextRun("This report contains sales data for Q4 2023.")
Dim bodyParagraph As New Paragraph()
bodyParagraph.AddTextRun(bodyRun)
' Add paragraphs to document
complexDoc.AddParagraph(titleParagraph)
complexDoc.AddParagraph(bodyParagraph)
' Save the document
complexDoc.SaveAs("assets/sales_report.docx")
出力Wordドキュメント

ステップ4:IronPDFを使用してWord文書をPDFに変換する
それでは、 IronPDFを使ってWord文書をPDFに変換してみましょう。
using IronPdf;
// Code to convert DOCX file to PDF using IronPDF
// Create a DocxToPdfRenderer instance
var renderer = new DocxToPdfRenderer();
// Render the DOCX document as a PDF
var pdf = renderer.RenderDocxAsPdf("assets/document.docx");
// Save the resulting PDF
pdf.SaveAs("assets/word.pdf");
using IronPdf;
// Code to convert DOCX file to PDF using IronPDF
// Create a DocxToPdfRenderer instance
var renderer = new DocxToPdfRenderer();
// Render the DOCX document as a PDF
var pdf = renderer.RenderDocxAsPdf("assets/document.docx");
// Save the resulting PDF
pdf.SaveAs("assets/word.pdf");
Imports IronPdf
' Code to convert DOCX file to PDF using IronPDF
' Create a DocxToPdfRenderer instance
Private renderer = New DocxToPdfRenderer()
' Render the DOCX document as a PDF
Private pdf = renderer.RenderDocxAsPdf("assets/document.docx")
' Save the resulting PDF
pdf.SaveAs("assets/word.pdf")
手順は簡単です。
DocxToPdfRendererを作成します- Word文書をPDFとしてレンダリングする
- 結果を保存する
ステップ5: IronPrintを使用してPDFを印刷する
最後に、 IronPrintを使ってPDFを印刷してみましょう。
using IronPrint;
using System.Collections.Generic;
// Code for Printing using IronPrint
// Fetch printer names available in the system
List<string> printerNames = Printer.GetPrinterNames();
// Configure print settings
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
if(printerName.Equals("Microsoft Print to PDF"))
{
printerSettings.PrinterName = printerName;
}
}
// Set paper size to A4 and configure margins
printerSettings.PaperSize = PaperSize.A4;
Margins margins = new Margins(30, 10);
printerSettings.PaperMargins = margins;
// Print the PDF with the specified settings
Printer.Print("assets/word.pdf", printerSettings);
using IronPrint;
using System.Collections.Generic;
// Code for Printing using IronPrint
// Fetch printer names available in the system
List<string> printerNames = Printer.GetPrinterNames();
// Configure print settings
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
if(printerName.Equals("Microsoft Print to PDF"))
{
printerSettings.PrinterName = printerName;
}
}
// Set paper size to A4 and configure margins
printerSettings.PaperSize = PaperSize.A4;
Margins margins = new Margins(30, 10);
printerSettings.PaperMargins = margins;
// Print the PDF with the specified settings
Printer.Print("assets/word.pdf", printerSettings);
Imports IronPrint
Imports System.Collections.Generic
' Code for Printing using IronPrint
' Fetch printer names available in the system
Private printerNames As List(Of String) = Printer.GetPrinterNames()
' Configure print settings
Private printerSettings As New PrintSettings()
For Each printerName As String In printerNames
If printerName.Equals("Microsoft Print to PDF") Then
printerSettings.PrinterName = printerName
End If
Next printerName
' Set paper size to A4 and configure margins
printerSettings.PaperSize = PaperSize.A4
Dim margins As New Margins(30, 10)
printerSettings.PaperMargins = margins
' Print the PDF with the specified settings
Printer.Print("assets/word.pdf", printerSettings)
このコードは:
Printer.GetPrinterNames()で使用可能なプリンターを取得します- 特定のプリンターを選択します
- 用紙サイズと余白を設定します
- PDFを印刷します

コピー、複数ページ、グレースケール、DPI をより細かく制御するには、これらのコード例を参照してください。 ユーザーとの対話のために、プリンターダイアログを有効にすることもできます。
IronPrintを使って印刷するメリットは何ですか?
IronPrintがC#の印刷タスクに優れている理由は以下のとおりです。
非同期印刷が重要な理由とは?
IronPrintは、印刷操作がアプリケーションの動作を妨げないようにする非同期機能を提供します。 長時間の印刷作業中も、ユーザーインターフェースの応答性は維持されます。
// Asynchronous printing example
using IronPrint;
using System.Threading.Tasks;
public async Task PrintDocumentAsync(string filePath)
{
PrintSettings settings = new PrintSettings
{
PrinterName = "Default Printer",
NumberOfCopies = 2
};
// Non-blocking print operation
await Printer.PrintAsync(filePath, settings);
Console.WriteLine("Print job completed!");
}
// Asynchronous printing example
using IronPrint;
using System.Threading.Tasks;
public async Task PrintDocumentAsync(string filePath)
{
PrintSettings settings = new PrintSettings
{
PrinterName = "Default Printer",
NumberOfCopies = 2
};
// Non-blocking print operation
await Printer.PrintAsync(filePath, settings);
Console.WriteLine("Print job completed!");
}
Imports IronPrint
Imports System.Threading.Tasks
Public Async Function PrintDocumentAsync(filePath As String) As Task
Dim settings As New PrintSettings With {
.PrinterName = "Default Printer",
.NumberOfCopies = 2
}
' Non-blocking print operation
Await Printer.PrintAsync(filePath, settings)
Console.WriteLine("Print job completed!")
End Function
印刷オプションはどのように機能性を向上させるのか?
Printer クラスは、PDF、PNG、JPG、TIFF、BMP など、さまざまなファイル形式に対応しています。この汎用性により、異なるコンテンツ形式でも、処理方法を変更することなく印刷できます。
どのプラットフォームにデプロイできますか?
IronPrintは、Windows、Android、iOS、macOSで動作します。 印刷コードはすべてのプラットフォームで一貫して動作するため、導入が容易です。
印刷設定でカスタマイズできる項目は何ですか?
PrintSettings クラスを通じて、以下を制御できます。
- 用紙のサイズと向き
- DPIと印刷品質
- コピーと照合
- 余白とレイアウト
- 両面印刷
- カスタムページ範囲
IronPrintは他のライブラリとどのように連携するのですか?
IronPrintは、 IronBarcodeやIronPDFなどの他のIron Software製品とスムーズに連携します。 一貫性のあるAPI設計により、ドキュメントの作成、変換、印刷を単一のワークフローで簡単に行うことができます。
なぜこのAPIはユーザーフレンドリーだと考えられているのか?
IronPrint の直感的なメソッド名と完全な IntelliSense サポートにより、すべての開発者が利用できます。 難しい学習を必要とせずに、印刷機能を迅速に追加できます。
どのような支援リソースが利用できますか?
Iron Softwareは、完全なドキュメント、サンプル、APIリファレンス、およびベストプラクティスを提供します。 彼らのサポートチームは、印刷機能を効果的に導入できるよう支援します。
IronPrintは印刷の制御性をどのように向上させるのか?
IronPrintを使えば、印刷のあらゆる側面を正確に制御できます。 出力が特定の要件を満たすように、用紙サイズ、余白、およびパラメーターを正確に設定してください。 プリンターの状態を監視し、エラーを処理することで、信頼性の高い印刷ジョブ管理を実現します。
次のステップは何ですか?
これで、C#アプリケーションでWord文書を作成し、PDFに変換し、印刷するために必要なものがすべて揃いました。 IronWord 、 IronPDF 、およびIronPrintは連携して、包括的な文書処理ソリューションを提供します。 ウェブ、モバイル、デスクトップ、コンソールなど、どのようなアプリケーションを開発する場合でも、これらのツールはドキュメントワークフローを簡素化します。
その他の印刷技術については、ドキュメントページをご覧ください。 バッチ印刷やカスタム印刷プロセッサなどの機能を活用して、アプリケーションの機能を向上させましょう。
IronPrint のライセンスは $799 から始まります。 ライブラリをダウンロードして、C#アプリケーションにProfessional印刷機能を今すぐ追加しましょう。
よくある質問
C# でフォーマットを失わずに Word ドキュメントを印刷するにはどうすれば良いですか?
C# でフォーマットを維持したまま Word ドキュメントを印刷するには、IronWord を使用してドキュメントを作成し、IronPDF を使用して PDF に変換し、IronPrint で印刷します。これにより、ドキュメントのフォーマットがプロセス全体で保たれます。
C# でのドキュメント印刷における IronPrint の利点は何ですか?
IronPrint は、非同期印刷、紙のサイズや向きなどのカスタマイズ可能な設定、クロスプラットフォームの互換性、その他の Iron Software のライブラリとシームレスに統合する機能を提供し、C# 環境での印刷タスクに高い堅牢性を提供します。
C# プロジェクトに IronWord、IronPDF、IronPrint を統合するにはどうすれば良いですか?
これらのライブラリを C# プロジェクトに統合するには、Visual Studio の NuGet パッケージ マネージャー コンソールを使用してインストールします。Install-Package IronWord, Install-Package IronPDF, Install-Package IronPrint を使用して、Word の作成、PDF 変換、および印刷の必要な機能を追加します。
IronPrint を使用する場合、印刷設定をカスタマイズできますか?
はい、IronPrint を使用すると、用紙サイズ、向き、DPI、コピー数、プリンター名、余白、グレースケール印刷など、様々な印刷設定をカスタマイズできます。印刷プロセスに対する完全な制御を提供します。
IronPrint はクロスプラットフォームの印刷タスクに適していますか?
IronPrint はクロスプラットフォーム対応を目的として設計されており、Windows、macOS、Android、および iOS で展開でき、様々な開発環境での利用に対応しています。
C# で Word ドキュメントを作成して印刷する手順は何ですか?
まず、IronWord を使用して Word ドキュメントを作成します。次に、それを IronPDF の DocxToPdfRenderer を使用して PDF に変換します。最後に、IronPrint を使用して PDF を印刷し、ドキュメントのフォーマットがプロセス全体で維持されるようにします。
IronPrint は C# アプリケーションでのドキュメント処理をどのように強化しますか?
IronPrint は包括的な印刷設定、非同期印刷、および他の Iron Software ライブラリとのシームレスな統合を提供し、C# アプリケーション内で効率的なドキュメント処理と印刷を促進します。
C# でのドキュメントの生成と印刷に推奨されるツールは何ですか?
Iron Software は、IronWord を使用してドキュメントを作成し、IronPDF を使用して PDF に変換し、IronPrint を使用して最終的に印刷することを推奨しています。この組み合わせにより、高品質の出力と使いやすさが確保されます。



