IronPDF C#で.NETにPDFを表示する方法
IronPDFは、MAUI用RasterizeToImageFilesを使用してページを画像にラスタライズし、WPFやWindows Forms内のWebView2などのホストコントロールを通じて表示します。 最適な選択は、作成するアプリの種類と、どれだけのビューアChromeが必要かによります。
"表示"は、これらの経路にまたがる異なる意味を持ちます。 MAUIビューアは、ツールバー付きの完全なインタラクティブコンポーネントです。 ラスター化経路では、各ページを任意のコントロールで表示できるイメージに変換します。 WebView2やデフォルトビューアルートは、ファイルをブラウザエンジンやユーザーがインストールしたPDFリーダーに渡します。 この記事は、それぞれを示し、何を提供しないかについて正直に述べています。
クイックスタート: IronPDFを使用してMAUIでPDFを表示する
まずIronPdf.Viewer.Maui NuGetパッケージを追加し、IronPdfViewにバインドします。 以下の一行でファイルをビューアコントロールにロードします。
最初にConfigureIronPdfViewにIronPDFライセンスキーを追加します。 MAUIビューワチュートリアルは、フルプロジェクトセットアップを案内します。
最小限のワークフロー(5ステップ)
- NuGetからIronPDFを.NET PDFレンダリング用にインストールする
- 表示パスを選択: MAUIビューア、画像にラスター化、WebView2、またはデフォルトのシステムビューア
- ASP.NETにHTML
iframeを使用してPDFを埋め込む - WPF、WinForms、またはBlazor表示用にPDFページをイメージ化してレンダリングする
System.Diagnostics.Process.Startを使用してユーザーのインストールされたリーダーでPDFを開く
ASP.NETとMVCでPDFを表示するには?
コントローラーアクションからPDFをサーブし、HTML iframeで埋め込みます。 ブラウザの組み込みPDFビューアがレンダリングを処理するため、ドキュメントはインラインで表示され、ページレイアウトはそのままです。 PDFがその場で生成される場合、IronPDFのHTMLからPDFに変換が、アクションが返すファイルを生成します。
// Controller action to serve PDF
public ActionResult ViewPdf()
{
var pdfPath = Server.MapPath("~/Content/sample.pdf");
return File(pdfPath, "application/pdf");
}
// In your Razor view
<iframe src="@Url.Action("ViewPdf")" width="100%" height="600px"></iframe>
// Controller action to serve PDF
public ActionResult ViewPdf()
{
var pdfPath = Server.MapPath("~/Content/sample.pdf");
return File(pdfPath, "application/pdf");
}
// In your Razor view
<iframe src="@Url.Action("ViewPdf")" width="100%" height="600px"></iframe>
Imports System.Web.Mvc
' Controller action to serve PDF
Public Function ViewPdf() As ActionResult
Dim pdfPath = Server.MapPath("~/Content/sample.pdf")
Return File(pdfPath, "application/pdf")
End Function
' In your Razor view
<iframe src="@Url.Action("ViewPdf")" width="100%" height="600px"></iframe>
テキスト選択、ズーム、ページナビゲーションをブラウザのデフォルトではなく制御する必要がある場合は、PDFページをイメージにレンダリングして表示するか、任意 for JavaScriptビューワを連絡することをお勧めします。
WPF、WinForms、またはBlazorでPDFページを画像として表示するにはどうすればよいですか?
<img>。 これはIronPDFネイティブの表示パスです。 任意のUIフレームワークおよびIronPDFがサポートするあらゆるオペレーティングシステムで同じように機能します。ホストブラウザコントロールに依存せず、プレーンなイメージファイルを生成するからです。
入力
:path=/static-assets/pdf/content-code-examples/how-to/net-pdf-viewer-rasterize.cs
using IronPdf;
// Load the PDF you want to display.
PdfDocument pdf = PdfDocument.FromFile("sample-report.pdf");
// Render every page to a PNG. The asterisk in the path is replaced with the page number,
// producing viewer-page-1.png, viewer-page-2.png, and so on. The last argument (100) is the DPI.
pdf.RasterizeToImageFiles("viewer-page-*.png", IronPdf.Imaging.ImageType.Png, 100);
// To show a page inside a GUI control without writing to disk, get in-memory bitmaps instead.
// ToBitmap returns one AnyBitmap per page; bind bitmaps[0] to a WPF Image or a WinForms PictureBox.
var bitmaps = pdf.ToBitmap();
bitmaps[0].SaveAs("viewer-firstpage.png");
Imports IronPdf
' Load the PDF you want to display.
Dim pdf As PdfDocument = PdfDocument.FromFile("sample-report.pdf")
' Render every page to a PNG. The asterisk in the path is replaced with the page number,
' producing viewer-page-1.png, viewer-page-2.png, and so on. The last argument (100) is the DPI.
pdf.RasterizeToImageFiles("viewer-page-*.png", IronPdf.Imaging.ImageType.Png, 100)
' To show a page inside a GUI control without writing to disk, get in-memory bitmaps instead.
' ToBitmap returns one AnyBitmap per page; bind bitmaps(0) to a WPF Image or a WinForms PictureBox.
Dim bitmaps = pdf.ToBitmap()
bitmaps(0).SaveAs("viewer-firstpage.png")
出力
インメモリーオプションとして、ToBitmapは各ページごとに1つの画像を返し、ディスクに触れることなくコントロールにバインドできます。 DPI引数を調整して、ファイルサイズをシャープネスとトレードオフし、ドキュメント生成時にIronPDFのレンダリングオプションを制御します。
WPFアプリケーションでPDFを表示するには?
WebView2コントロールにPDFをホストし、Microsoft EdgeのChromiumエンジンを使用し、専用のPDFビューアを含んでいます(ツールバー、ズーム、印刷も含む)。 ドキュメントをディスクに保存し、ファイルURIにコントロールをナビゲートします。 WebView2は、廃止されたInternet Explorerエンジンに依存していた古いWebBrowserコントロールの現在の代替です。
:path=/static-assets/pdf/content-code-examples/how-to/net-pdf-viewer-wpf-viewer.cs
// WPF: display a PDF using the WebView2 control (Microsoft Edge / Chromium).
// Install the NuGet package Microsoft.Web.WebView2 and add a <wv2:WebView2 x:Name="pdfWebView" />
// element to your XAML (xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf").
// WebView2 renders PDFs with the same built-in viewer as the Edge browser (toolbar, zoom, print).
using System;
using System.IO;
// Save the IronPDF-generated document to disk first, then point WebView2 at it.
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello IronPDF</h1>");
string pdfPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "document.pdf");
pdf.SaveAs(pdfPath);
// pdfWebView is the WebView2 control declared in your XAML.
// EnsureCoreWebView2Async must complete before navigating.
await pdfWebView.EnsureCoreWebView2Async();
pdfWebView.CoreWebView2.Navigate(new Uri(pdfPath).AbsoluteUri);
// Legacy alternative: the older System.Windows.Controls.WebBrowser control still works on
// Windows machines that have a PDF handler installed, but it relies on the deprecated Internet
// Explorer engine and is not recommended for new applications. Prefer WebView2 above.
Imports System
Imports System.IO
Imports IronPdf
' WPF: display a PDF using the WebView2 control (Microsoft Edge / Chromium).
' Install the NuGet package Microsoft.Web.WebView2 and add a <wv2:WebView2 x:Name="pdfWebView" />
' element to your XAML (xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf").
' WebView2 renders PDFs with the same built-in viewer as the Edge browser (toolbar, zoom, print).
' Save the IronPDF-generated document to disk first, then point WebView2 at it.
Dim pdf = New ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello IronPDF</h1>")
Dim pdfPath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "document.pdf")
pdf.SaveAs(pdfPath)
' pdfWebView is the WebView2 control declared in your XAML.
' EnsureCoreWebView2Async must complete before navigating.
Await pdfWebView.EnsureCoreWebView2Async()
pdfWebView.CoreWebView2.Navigate(New Uri(pdfPath).AbsoluteUri)
' Legacy alternative: the older System.Windows.Controls.WebBrowser control still works on
' Windows machines that have a PDF handler installed, but it relies on the deprecated Internet
' Explorer engine and is not recommended for new applications. Prefer WebView2 above.
WindowsフォームでPDFを表示するには?
WebView2コントロールをフォームに追加し、保存したPDFにポイントします。WPFと全く同じです。 コントロールは非同期的に初期化されるため、Navigateを呼び出します。 これにより、WinFormsアプリはサードパーティコンポーネントを束縛することなく、同じChromiumベースのビューアを提供します。
:path=/static-assets/pdf/content-code-examples/how-to/net-pdf-viewer-winforms-viewer.cs
// Windows Forms: display a PDF using the WebView2 control (Microsoft Edge / Chromium).
// Install the NuGet package Microsoft.Web.WebView2, then drag a WebView2 control onto your form
// (or add it in code) and name it pdfWebView.
using System;
using System.IO;
// Generate or load the PDF with IronPDF, then save it so WebView2 can open the file.
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello IronPDF</h1>");
string pdfPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "document.pdf");
pdf.SaveAs(pdfPath);
// pdfWebView is the WebView2 control on your form.
// Initialize the runtime, then navigate to the local file URI.
await pdfWebView.EnsureCoreWebView2Async();
pdfWebView.CoreWebView2.Navigate(new Uri(pdfPath).AbsoluteUri);
// Legacy alternative: the System.Windows.Forms.WebBrowser control can host a PDF when a system
// PDF handler is registered, but it uses the deprecated Internet Explorer engine. Use WebView2
// for new projects so the viewer works consistently across modern Windows installs.
Imports System
Imports System.IO
Imports IronPdf
' Generate or load the PDF with IronPDF, then save it so WebView2 can open the file.
Dim pdf = New ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello IronPDF</h1>")
Dim pdfPath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "document.pdf")
pdf.SaveAs(pdfPath)
' pdfWebView is the WebView2 control on your form.
' Initialize the runtime, then navigate to the local file URI.
Await pdfWebView.EnsureCoreWebView2Async()
pdfWebView.CoreWebView2.Navigate(New Uri(pdfPath).AbsoluteUri)
' Legacy alternative: the System.Windows.Forms.WebBrowser control can host a PDF when a system
' PDF handler is registered, but it uses the deprecated Internet Explorer engine. Use WebView2
' for new projects so the viewer works consistently across modern Windows installs.
ブラウザコントロールを一切ホストしない場合は、上記セクションの画像ベースのアプローチを直接PictureBoxに落とし込み、WebView2ランタイムの依存関係を完全に回避できます。
デフォルトのシステム PDF ビューアで PDF を表示するには?
ファイルパスをSystem.Diagnostics.Process.Startに渡して、ユーザーがブラウザやAdobe Acrobatなどでデフォルト設定したリーダーでPDFを開きます。 これは、埋め込みではなく外部アプリケーションにレンダリングを渡すため、ファイルの表示のみが必要なユーティリティとバッチツールに適しています。
:path=/static-assets/pdf/content-code-examples/how-to/net-pdf-viewer-default-pdf-viewer.cs
using IronPdf;
// Render any HTML fragment or document to HTML
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
var outputPath = "ChromePdfRenderer.pdf";
// Export PDF document
pdf.SaveAs(outputPath);
// This neat trick opens our PDF file so we can see the result in our default PDF viewer
System.Diagnostics.Process.Start(outputPath);
Imports IronPdf
' Render any HTML fragment or document to HTML
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>")
Private outputPath = "ChromePdfRenderer.pdf"
' Export PDF document
pdf.SaveAs(outputPath)
' This neat trick opens our PDF file so we can see the result in our default PDF viewer
System.Diagnostics.Process.Start(outputPath)
本番環境では、欠落したPDFハンドラがアプリをクラッシュさせないように呼び出しをラップします:
try
{
var psi = new System.Diagnostics.ProcessStartInfo
{
FileName = outputPath,
UseShellExecute = true
};
System.Diagnostics.Process.Start(psi);
}
catch (Exception ex)
{
// Handle the case where no PDF viewer is installed
MessageBox.Show($"Unable to open PDF: {ex.Message}");
}
try
{
var psi = new System.Diagnostics.ProcessStartInfo
{
FileName = outputPath,
UseShellExecute = true
};
System.Diagnostics.Process.Start(psi);
}
catch (Exception ex)
{
// Handle the case where no PDF viewer is installed
MessageBox.Show($"Unable to open PDF: {ex.Message}");
}
Imports System.Diagnostics
Imports System.Windows.Forms
Try
Dim psi As New ProcessStartInfo With {
.FileName = outputPath,
.UseShellExecute = True
}
Process.Start(psi)
Catch ex As Exception
' Handle the case where no PDF viewer is installed
MessageBox.Show($"Unable to open PDF: {ex.Message}")
End Try
結論
ここでの各表示パスは、ポータビリティのためにインタラクティブ性を犠牲にしています:MAUIビューワーは完全なツールバーを提供し、画像へのラスタライズはあらゆるプラットフォームのあらゆるUIで機能し、WebView2はEdgeエンジンを再利用し、Process.Startはユーザーのリーダーに委ねます。 単一の回答を強制するのではなく、あなたのアプリに一致するものを選びます。
表示のほとんどが生成されたドキュメントから始まるため、インタラクティブなツールバーが必要な場合は、これらの技術を完全なMAUIビューワーチュートリアルと組み合わせてください。
よくある質問
.NET MAUIアプリケーションでPDFを表示するには?
IronPDFはIronPdf.Viewer.Maui NuGetパッケージのMAUIプロジェクト用のインタラクティブPDFビューアコンポーネントを出荷しています。このパッケージをインストールし、ConfigureIronPdfView()を呼び出した後、ファイルまたはストリームから読み込んでIronPdfViewコントロールにPDFをバインドできます。このMAUIコンポーネントはビルトインツールバーを提供する唯一のパスです。
ASP.NETウェブアプリケーションでPDFを表示する最も簡単な方法は何ですか?
ASP.NETアプリケーションでは、IronPDFはブラウザウィンドウまたはiframeを通してPDFを表示することができます。iframeのアプローチはPDFコンテンツをインラインで表示しながらアプリケーションのレイアウトを維持するため、特に効果的です。また、IronPDFのHTMLからPDFへの変換機能を使って、動的なPDFをその場で生成して表示することもできます。
PDF表示をWPFやWinFormsアプリケーションに統合できますか?
はい。WPFおよびWinFormsの場合、WebView2コントロールをホストし、保存されたPDFにナビゲートします。WebView2はMicrosoft Edgeのクロムエンジンを使用し、自身のツールバー、ズーム、印刷を含みます。
システムのデフォルトのPDFビューアを.NETアプリケーションで使用することは可能ですか?
もちろんです。IronPDFはSystem.Diagnostics.Processを使用してシステムのデフォルトPDFビューアとの統合をサポートしています。このアプローチにより、ユーザーの好みのPDFアプリケーションでPDFを開きながら、IronPDFを使って事前にPDFドキュメントを生成、操作、準備することができます。
閲覧だけでなく、どのようなPDFの追加機能が利用できますか?
IronPDFはドキュメントセキュリティのためのデジタル署名、インタラクティブPDFのためのフォーム入力機能、ファイルサイズを削減するためのPDF圧縮、動的コンテンツ生成のためのHTMLからPDFへの変換、およびさまざまな形式でのPDFの保存/エクスポートを含む幅広いPDF機能を提供しています。

