# IronPDF C#で.NETにPDFを表示する方法
IronPDFは、MAUI用`RasterizeToImageFiles`を使用してページを画像にラスタライズし、WPFやWindows Forms内のWebView2などのホストコントロールを通じて表示します。 最適な選択は、作成するアプリの種類と、どれだけのビューアChromeが必要かによります。
"表示"は、これらの経路にまたがる異なる意味を持ちます。 MAUIビューアは、ツールバー付きの完全なインタラクティブコンポーネントです。 ラスター化経路では、各ページを任意のコントロールで表示できるイメージに変換します。 WebView2やデフォルトビューアルートは、ファイルをブラウザエンジンやユーザーがインストールしたPDFリーダーに渡します。 この記事は、それぞれを示し、何を提供しないかについて正直に述べています。
*as-heading:2(クイックスタート: IronPDFを使用してMAUIでPDFを表示する)*
まず`IronPdf.Viewer.Maui` NuGetパッケージを追加し、`IronPdfView`にバインドします。 以下の一行でファイルをビューアコントロールにロードします。
```cs
:title=Load a PDF into the MAUI viewer in one line!
new IronPdf.Viewer.Maui.IronPdfView { Source = IronPdf.Viewer.Maui.IronPdfViewSource.FromFile("document.pdf") };
```
最初に`ConfigureIronPdfView`にIronPDFライセンスキーを追加します。 [MAUIビューワチュートリアル](/tutorials/pdf-viewing/)は、フルプロジェクトセットアップを案内します。
<div class="hsg-featured-snippet">
<h3>最小限のワークフロー(5ステップ)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/IronPdf/">NuGetからIronPDFを.NET PDFレンダリング用にインストールする</a></li>
<li>表示パスを選択: MAUIビューア、画像にラスター化、WebView2、またはデフォルトのシステムビューア</li>
<li>ASP.NETにHTML <code>iframe</code>を使用してPDFを埋め込む</li>
<li>WPF、WinForms、またはBlazor表示用にPDFページをイメージ化してレンダリングする</li>
<li><code>System.Diagnostics.Process.Start</code>を使用してユーザーのインストールされたリーダーでPDFを開く</li>
</ol>
</div>
<br class="clear" />
## ASP.NETとMVCでPDFを表示するには?
コントローラーアクションからPDFをサーブし、HTML `iframe`で埋め込みます。 ブラウザの組み込みPDFビューアがレンダリングを処理するため、ドキュメントはインラインで表示され、ページレイアウトはそのままです。 PDFがその場で生成される場合、IronPDFの[HTMLからPDFに変換](/how-to/html-string-to-pdf/)が、アクションが返すファイルを生成します。
```csharp
// 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>
```
テキスト選択、ズーム、ページナビゲーションをブラウザのデフォルトではなく制御する必要がある場合は、PDFページをイメージにレンダリングして表示するか、任意 for JavaScriptビューワを連絡することをお勧めします。
<hr class="separator" />
## WPF、WinForms、またはBlazorでPDFページを画像として表示するにはどうすればよいですか?
`<img>`。 これはIronPDFネイティブの表示パスです。 任意のUIフレームワークおよびIronPDFがサポートするあらゆるオペレーティングシステムで同じように機能します。ホストブラウザコントロールに依存せず、プレーンなイメージファイルを生成するからです。
### 入力
<iframe loading="lazy" src="/static-assets/pdf/how-to/net-pdf-viewer/sample-report.pdf" width="100%" height="500px"></iframe>
```csharp
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");
```
### 出力
<img src="/static-assets/pdf/how-to/net-pdf-viewer/rasterized-page-1.png" alt=".NET UI コントロールでの表示用に PNG 画像へラスタライズされた、サンプルレポート PDF の 1 ページ目" width="100%" class="img-responsive add-shadow" />
インメモリーオプションとして、`ToBitmap`は各ページごとに1つの画像を返し、ディスクに触れることなくコントロールにバインドできます。 DPI引数を調整して、ファイルサイズをシャープネスとトレードオフし、ドキュメント生成時にIronPDFの[レンダリングオプション](/how-to/rendering-options/)を制御します。
<hr class="separator" />
## WPFアプリケーションでPDFを表示するには?
WebView2コントロールにPDFをホストし、Microsoft EdgeのChromiumエンジンを使用し、専用のPDFビューアを含んでいます(ツールバー、ズーム、印刷も含む)。 ドキュメントをディスクに保存し、ファイルURIにコントロールをナビゲートします。 WebView2は、廃止されたInternet Explorerエンジンに依存していた古い`WebBrowser`コントロールの現在の代替です。
```csharp
// 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.
```
[[w:(WebView2はターゲットマシンにMicrosoft Edge WebView2ランタイムを必要とします。現在のWindows 11ビルドにはプレインストールされています; 古いシステムには、インストーラとともにエバーグリーンブートストラッパーを配送します。)]]
<hr class="separator" />
## WindowsフォームでPDFを表示するには?
WebView2コントロールをフォームに追加し、保存したPDFにポイントします。WPFと全く同じです。 コントロールは非同期的に初期化されるため、`Navigate`を呼び出します。 これにより、WinFormsアプリはサードパーティコンポーネントを束縛することなく、同じChromiumベースのビューアを提供します。
```csharp
// 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.
```
ブラウザコントロールを一切ホストしない場合は、上記セクションの画像ベースのアプローチを直接`PictureBox`に落とし込み、WebView2ランタイムの依存関係を完全に回避できます。
<hr class="separator" />
## デフォルトのシステム PDF ビューアで PDF を表示するには?
ファイルパスを`System.Diagnostics.Process.Start`に渡して、ユーザーがブラウザやAdobe Acrobatなどでデフォルト設定したリーダーでPDFを開きます。 これは、埋め込みではなく外部アプリケーションにレンダリングを渡すため、ファイルの表示のみが必要なユーティリティとバッチツールに適しています。
```csharp
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);
```
本番環境では、欠落したPDFハンドラがアプリをクラッシュさせないように呼び出しをラップします:
```csharp
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}");
}
```
## 結論
ここでの各表示パスは、ポータビリティのためにインタラクティブ性を犠牲にしています:MAUIビューワーは完全なツールバーを提供し、画像へのラスタライズはあらゆるプラットフォームのあらゆるUIで機能し、WebView2はEdgeエンジンを再利用し、`Process.Start`はユーザーのリーダーに委ねます。 単一の回答を強制するのではなく、あなたのアプリに一致するものを選びます。
表示のほとんどが生成されたドキュメントから始まるため、インタラクティブなツールバーが必要な場合は、これらの技術を完全な[MAUIビューワーチュートリアル](/tutorials/pdf-viewing/)と組み合わせてください。
// Controller action to serve PDFpublic ActionResultViewPdf(){ var pdfPath = Server.MapPath("~/Content/sample.pdf"); returnFile(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>
ImportsSystem.Web.Mvc' Controller action to serve PDFPublic Function ViewPdf() AsActionResult Dim pdfPath = Server.MapPath("~/Content/sample.pdf") ReturnFile(pdfPath, "application/pdf")End Function' 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ビューワを連絡することをお勧めします。
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");
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");
// 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.
// 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.
// 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.
// 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.
using IronPdf;// Render any HTML fragment or document to HTMLChromePdfRenderer renderer = new ChromePdfRenderer();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");var outputPath = "ChromePdfRenderer.pdf";// Export PDF documentpdf.SaveAs(outputPath);// This neat trick opens our PDF file so we can see the result in our default PDF viewerSystem.Diagnostics.Process.Start(outputPath);
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);
ImportsIronPdf' Render any HTML fragment or document to HTMLPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>")Private outputPath = "ChromePdfRenderer.pdf"' Export PDF documentpdf.SaveAs(outputPath)' This neat trick opens our PDF file so we can see the result in our default PDF viewerSystem.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 installedMessageBox.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}");
}
ImportsSystem.DiagnosticsImportsSystem.Windows.FormsTry Dim psi As New ProcessStartInfoWith { .FileName = outputPath, .UseShellExecute = True }Process.Start(psi)Catch ex AsException ' Handle the case where no PDF viewer is installedMessageBox.Show($"Unable to open PDF: {ex.Message}")EndTry
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
How can I open a PDF in the default system viewer using IronPDF?
Use System.Diagnostics.Process.Start with the PDF file path to open it in the user's default PDF reader, such as a browser or Adobe Acrobat.
Is it possible to display PDFs in Blazor applications with IronPDF?
Yes, you can convert each PDF page to an image using IronPDF's RasterizeToImageFiles, and display those images using an img tag in a Blazor component.
What should I do if the default PDF viewer is not installed on the user's system?
Wrap the System.Diagnostics.Process.Start call in a try-catch block to handle cases where a PDF viewer is missing, ensuring your application does not crash.
How can IronPDF's MAUI viewer enhance my application's PDF viewing experience?
The MAUI viewer provides a full interactive component with a toolbar, allowing users to interact with the PDF directly within your app.
Can I use IronPDF to integrate PDF viewing capabilities without depending on browser controls?
Yes, by rasterizing PDF pages to images, you can integrate viewing capabilities in any UI framework without relying on browser-based controls.