透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
マイクロソフトが開発したオープンソースのクロスプラットフォームフレームワークである.NETコアは、その柔軟性、パフォーマンス、クラウドベースのアプリケーションのサポートで人気を集めている。 しかし、特にPDFドキュメントを印刷するような作業を行う場合、開発者は堅牢で機能が充実したPDFライブラリを必要とします。 そこでIronPDFが開発者をサポートします。
IronPDF は、.NETフレームワーク (.NET CoreおよびASP.NET Coreを含む) 用に設計された包括的なライブラリで、PDF文書を扱うプロセスを簡素化します。 PDFファイルの作成と操作ができるだけでなく、これらの文書を直接プリンターで印刷したり、印刷に適した形式に変換したりと、シームレスな印刷方法を提供します。
このチュートリアルでは、.NET Core環境におけるIronPDFの機能を掘り下げていきます。 プロジェクトのセットアップや最初のPDFドキュメントの作成から、印刷設定の構成や高度な印刷機能の実装まで、各ステップを通してご案内します。このチュートリアルは、.NETコアアプリケーションでPDFファイルの印刷を効率的に処理するために必要な知識とツールを習得することを目的としています。
Visual StudioでASP.NET Core Webプロジェクトを作成する
NuGetパッケージマネージャを使用してPDFライブラリをインストールする
PDF 文書を コ ン ト ロ ー ラ に作成ま たは読み込み
.NETアプリケーションでPDFを扱うには、まずIronPDF ライブラリを統合します。 IronPDFは、.NET開発者が簡単にPDFドキュメントを作成、編集、そして最も重要な印刷ができる強力で多機能なライブラリです。 では、インストール手順を説明しよう:
.NET Core プロジェクトの作成: Visual Studio を開き、「新しいプロジェクトの作成」を選択します。プロジェクトテンプレート選択ウィンドウで、「すべてのプラットフォーム」の下にある「Web」でフィルターし、「ASP.NET Core Web アプリ」を選択します。
IronPDF のインストール: 「NuGet パッケージマネージャー」に移動し、プロジェクトにインストールするために「IronPDF」を検索します。 IronPDFライブラリが正しくインストールされ、プロジェクトファイルで参照されていることを確認してください。 コード内にusing IronPdf;
のような適切なusing
ステートメントを含める必要があります。
ASP.NET Core WebアプリケーションでIronPDFを使ってPDFドキュメントを作成するには、まずコントローラにコードを追加します。 簡単な例を挙げよう:
プロジェクトに新しいコントローラを作成し、PDF作成要求の処理を担当させます。 例えばPdfController
と名付けることができます。
新しいコントローラー内で、CreatePdf
という名前のアクションメソッドを書き、その結果としてPDFファイルを返すようにします。
using IronPdf;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
public class PdfController : Controller
{
public IActionResult CreatePdf()
{
// Create a new PDF document
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a simple PDF document created in an ASP.NET Core web app.</p>");
// Save the PDF to the server's memory
var content = pdf.Stream.ToArray();
// Return the PDF to the browser as a file download
return File(content, "application/pdf", "MyFirstPdf.pdf");
}
}
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;
namespace YourProjectName.Controllers
{
public class PdfController : Controller
{
public IActionResult CreatePdf()
{
// Create a new PDF document
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a simple PDF document created in an ASP.NET Core web app.</p>");
// Save the PDF to the server's memory
var content = pdf.Stream.ToArray();
// Return the PDF to the browser as a file download
return File(content, "application/pdf", "MyFirstPdf.pdf");
}
}
}
Imports IronPdf
Imports Microsoft.AspNetCore.Mvc
Namespace YourProjectName.Controllers
Public Class PdfController
Inherits Controller
Public Function CreatePdf() As IActionResult
' Create a new PDF document
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a simple PDF document created in an ASP.NET Core web app.</p>")
' Save the PDF to the server's memory
Dim content = pdf.Stream.ToArray()
' Return the PDF to the browser as a file download
Return File(content, "application/pdf", "MyFirstPdf.pdf")
End Function
End Class
End Namespace
アプリケーションを起動し、PdfController
内の CreatePdf
アクションに移動します。 たとえば、アプリケーションがポート5000
のlocalhost
で実行されている場合、ウェブブラウザでhttp://localhost:<Your-Port>/Pdf/CreatePdf
にアクセスしてください。
URLにアクセスすると、PDF文書が生成され、ウェブブラウザからダウンロードされます。 生成されたPDFをご覧になりたい場合は、お使いのコンピュータでPDFビューアを使用してお読みください。
ASP.NET Core Web AppでPDFドキュメントの作成をマスターしたら、次のステップは印刷機能を実装することです。 IronPDFはプロジェクト内でPDFドキュメントを印刷する簡単な方法を提供します。
PDF文書を印刷するには、アプリケーション内でプリンタ設定を行う必要があります。 IronPDFでは、ローカルにインストールされたプリンターまたはネットワークプリンターの名前でプリンターを指定することができます。 さらに、用紙ソースや向きなど、その他の設定を定義することもできます。
こちらは、プリンタ設定を構成し印刷ジョブを開始する、PdfController
クラスプログラム内の例としてのメソッドです:
using IronPdf;
using Microsoft.AspNetCore.Mvc;
public class PdfController : Controller
{
public IActionResult PrintPdf()
{
// Assuming 'htmlContent' is the HTML string you want to print
var htmlContent = "<h1>Invoice</h1><p>Thank you for your business!</p>";
// Render the HTML content to a PDF in memory
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Get the PrintDocument from the PDF
var printDoc = pdf.GetPrintDocument();
// Set the printer name
printDoc.PrinterSettings.PrinterName = "Your Printer Name"; // Replace with your printer's name
// Optional: Set other printer settings
// printDoc.PrinterSettings.Copies = 2;
// printDoc.DefaultPageSettings.Landscape = true;
// Print the document
printDoc.Print();
// Return a response to the client, e.g., a confirmation message
return Content("The document has been sent to the printer.");
}
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;
public class PdfController : Controller
{
public IActionResult PrintPdf()
{
// Assuming 'htmlContent' is the HTML string you want to print
var htmlContent = "<h1>Invoice</h1><p>Thank you for your business!</p>";
// Render the HTML content to a PDF in memory
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Get the PrintDocument from the PDF
var printDoc = pdf.GetPrintDocument();
// Set the printer name
printDoc.PrinterSettings.PrinterName = "Your Printer Name"; // Replace with your printer's name
// Optional: Set other printer settings
// printDoc.PrinterSettings.Copies = 2;
// printDoc.DefaultPageSettings.Landscape = true;
// Print the document
printDoc.Print();
// Return a response to the client, e.g., a confirmation message
return Content("The document has been sent to the printer.");
}
}
Imports IronPdf
Imports Microsoft.AspNetCore.Mvc
Public Class PdfController
Inherits Controller
Public Function PrintPdf() As IActionResult
' Assuming 'htmlContent' is the HTML string you want to print
Dim htmlContent = "<h1>Invoice</h1><p>Thank you for your business!</p>"
' Render the HTML content to a PDF in memory
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
' Get the PrintDocument from the PDF
Dim printDoc = pdf.GetPrintDocument()
' Set the printer name
printDoc.PrinterSettings.PrinterName = "Your Printer Name" ' Replace with your printer's name
' Optional: Set other printer settings
' printDoc.PrinterSettings.Copies = 2;
' printDoc.DefaultPageSettings.Landscape = true;
' Print the document
printDoc.Print()
' Return a response to the client, e.g., a confirmation message
Return Content("The document has been sent to the printer.")
End Function
End Class
Your Printer Name "は、お使いの環境での実際のプリンタ名に置き換えてください。 プリンターは、ASP.NETコアアプリケーションが実行されているサーバーからアクセスできる必要があります。 プログラムを実行し、次のURL「**https://localhost:<Your-Port>/Pdf/PrintPdf**
」にアクセスすると、次のメッセージが表示されます:
PDFがプリンターに送られることを意味します。
このチュートリアルを通して、ASP.NET Coreアプリケーションのコンテキスト内でIronPDFの機能と性能を探ってきました。 IronPDFによるプロジェクトのセットアップから、PDFドキュメントの作成と操作、そしてこれらのドキュメントの印刷に関わるより複雑なプロセスまで、IronPDFは.NETコアでPDFを扱うための堅牢で汎用性の高いツールであることが証明されています。
IronPDFの利用に興味がある方は、ライブラリが無料トライアルを提供しており、コミットする前にその機能を評価できることを知っておく価値があります。 ニーズに合うと感じた場合、IronPDFのライセンスは$749から始まり、小規模および大規模プロジェクトの両方に対応したスケーラブルなソリューションを提供します。 以下にIronXLライセンスの価格を表示しています。詳細を見るにはこちらをクリックしてください。