IronPDF C#で.NETにPDFを表示する方法

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDFは、MAUI用RasterizeToImageFilesを使用してページを画像にラスタライズし、WPFやWindows Forms内のWebView2などのホストコントロールを通じて表示します。 最適な選択は、作成するアプリの種類と、どれだけのビューアChromeが必要かによります。

"表示"は、これらの経路にまたがる異なる意味を持ちます。 MAUIビューアは、ツールバー付きの完全なインタラクティブコンポーネントです。 ラスター化経路では、各ページを任意のコントロールで表示できるイメージに変換します。 WebView2やデフォルトビューアルートは、ファイルをブラウザエンジンやユーザーがインストールしたPDFリーダーに渡します。 この記事は、それぞれを示し、何を提供しないかについて正直に述べています。

クイックスタート: IronPDFを使用してMAUIでPDFを表示する

まずIronPdf.Viewer.Maui NuGetパッケージを追加し、IronPdfViewにバインドします。 以下の一行でファイルをビューアコントロールにロードします。

  1. IronPDF をNuGetパッケージマネージャでインストール

    PM > Install-Package IronPdf
  2. このコード スニペットをコピーして実行します。

    new IronPdf.Viewer.Maui.IronPdfView { Source = IronPdf.Viewer.Maui.IronPdfViewSource.FromFile("document.pdf") };
  3. 実際の環境でテストするためにデプロイする

    今日プロジェクトで IronPDF を使い始めましょう無料トライアル

    arrow pointer

最初にConfigureIronPdfViewにIronPDFライセンスキーを追加します。 MAUIビューワチュートリアルは、フルプロジェクトセットアップを案内します。


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>
$vbLabelText   $csharpLabel

テキスト選択、ズーム、ページナビゲーションをブラウザのデフォルトではなく制御する必要がある場合は、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")
$vbLabelText   $csharpLabel

出力

.NET UI コントロールでの表示用に PNG 画像へラスタライズされた、サンプルレポート PDF の 1 ページ目

インメモリーオプションとして、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.
$vbLabelText   $csharpLabel

警告WebView2はターゲットマシンにMicrosoft Edge WebView2ランタイムを必要とします。現在のWindows 11ビルドにはプレインストールされています; 古いシステムには、インストーラとともにエバーグリーンブートストラッパーを配送します。


Icon Quote related to WPFアプリケーションでPDFを表示するには?

私のお気に入りのこの種のライブラリはIronPDFです。PDFファイルの迅速で効率的な操作が可能です。また、PDF/A形式へのエクスポートやPDF文書へのデジタル署名といった多くの貴重な機能も備えています。

Milan Jovanovic related to WPFアプリケーションでPDFを表示するには?

Milan Jovanovic

Microsoft MVP

ケーススタディを見る
Icon Quote related to WPFアプリケーションでPDFを表示するには?

IronOCRのおかげで私たちは年間$40,000を手作業の処理から節約し、生産性を向上させ、高影響のタスクにリソースを充てることができます。非常にお勧めします。

Brent Matzelle related to WPFアプリケーションでPDFを表示するには?

Brent Matzelle

最高技術責任者, OPYN

ケーススタディを見る
Icon Quote related to WPFアプリケーションでPDFを表示するには?

IronSuiteは私たちの業務において重要な役割を果たしています。これらは、フロアプランの作成や在庫管理の改善を含め、ビジネス全体の効率を向上させるツールです。

David Jones related to WPFアプリケーションでPDFを表示するには?

David Jones

リードソフトウェアエンジニア、Agorus Build

ケーススタディを見る

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.
$vbLabelText   $csharpLabel

ブラウザコントロールを一切ホストしない場合は、上記セクションの画像ベースのアプローチを直接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)
$vbLabelText   $csharpLabel

本番環境では、欠落した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
$vbLabelText   $csharpLabel

結論

ここでの各表示パスは、ポータビリティのためにインタラクティブ性を犠牲にしています: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機能を提供しています。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 20,296,129 | バージョン: 2026.7 リリースされたばかり
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package IronPdf
サンプルを実行するHTML が PDF に変換されるのを確認します。