.NET에서 IronPDF C#으로 PDF를 보는 방법
IronPDF는 MAUI를 위한 IronPdf.Viewer.Maui 컨트롤을 통해 .NET 응용프로그램에서 PDF를 표시하고, 모든 UI 프레임워크에서 사용할 수 있도록 페이지를 이미지를 통해 RasterizeToImageFiles을 사용하여 래스터화하며, WPF와 Windows Forms의 WebView2와 같은 호스트 컨트롤을 통해 사용할 수 있습니다. 적절한 선택은 당신이 어떤 종류의 앱을 만들고 있으며 얼마나 많은 뷰어 Chrome이 필요한지에 달려 있습니다.
여기서 '보기'라는 것은 각각의 경로에서 다른 의미를 가집니다. MAUI 뷰어는 툴바가 있는 완전한 인터랙티브 컴포넌트입니다. 래스터화 경로는 각 페이지를 이미지로 변환하여 모든 제어에서 표시할 수 있게 합니다. WebView2 및 기본 뷰어 경로는 파일을 브라우저 엔진이나 사용자가 설치한 PDF 리더에 전달합니다. 이 기사는 각 옵션을 보여주며, 제공하는 것과 제공하지 않는 것을 솔직하게 설명합니다.
빠른 시작: IronPDF로 MAUI에서 PDF 보기
IronPdf.Viewer.Maui NuGet 패키지를 추가하고 ConfigureIronPdfView()을(를) MauiProgram.cs에서 호출한 다음, PDF를 IronPdfView에 바인드하십시오. 아래의 한 줄 코드는 파일을 뷰어 제어에 로드합니다.
먼저 Install-Package IronPdf.Viewer.Maui 를 사용하여 패키지를 설치한 후 체험판 배너를 제거하기 위해 ConfigureIronPdfView에 IronPDF 라이선스 키를 추가합니다. MAUI 뷰어 튜토리얼은 전체 프로젝트 설정을 안내합니다.
최소 워크플로우(5단계)
- IronPDF를 NuGet에서 설치하여 .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 페이지를 이미지로 렌더링 (아래에 표시됨)하여 표시하거나, 당신이 선택한 JavaScript 뷰어를 연결합니다.
WPF, WinForms 또는 Blazor에서 PDF 페이지를 이미지로 표시하는 방법은?
RasterizeToImageFiles을 호출하여 각 PDF 페이지를 PNG로 변환한 다음, 해당 이미지를 원하는 컨트롤에 표시하십시오: WPF Image, WinForms PictureBox 또는 Blazor 구성 요소의 <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은 각 페이지에 대해 하나의 이미지를 반환하여 디스크를 건드리지 않고도 컨트롤에 바인딩할 수 있습니다. 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 Forms에서 PDF 파일을 어떻게 볼 수 있나요?
양식에 WebView2 컨트롤을 놓고 저장된 PDF로 재확인하시면 됩니다, WPF에서 한 것처럼요. 컨트롤이 비동기적으로 초기화되므로 EnsureCoreWebView2Async를 기다렸다가 Navigate을 호출하십시오. 이것은 Chromium 기반의 뷰어를 추가적인 타사 컴포넌트 없이 WinForms 앱에 제공합니다.
: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에 전달하여 사용자가 기본값으로 설정한 리더에서 PDF를 엽니다. 예를 들어 브라우저 또는 Adobe Acrobat. 이렇게 하면 렌더링이 외부 애플리케이션에 전달되어 작업이 완료된 파일만 보여주면 되는 유틸리티 및 일괄 처리 도구에 적합하게 됩니다.
: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는 MAUI 프로젝트를 위한 상호작용적인 PDF 뷰어 구성을 IronPdf.Viewer.Maui NuGet 패키지로 제공합니다. 패키지를 설치하고 ConfigureIronPdfView()를 호출한 후, IronPdfViewSource.FromFile을 사용하여 파일에서 IronPdfView 컨트롤에 PDF를 바인딩하거나 스트림에서 로드할 수 있습니다. 이 MAUI 구성 요소는 내장된 툴바를 제공하는 유일한 경로입니다; 데스크탑과 웹에서는 WebView2를 호스팅하거나 iframe을 삽입하거나 페이지를 이미지로 래스터화하여 PDF를 봅니다.
ASP.NET 웹 애플리케이션에서 PDF 파일을 보는 가장 쉬운 방법은 무엇인가요?
ASP.NET 애플리케이션의 경우, IronPDF는 브라우저 창 또는 iframe을 통해 PDF를 볼 수 있도록 지원합니다. iframe 방식은 애플리케이션 레이아웃을 유지하면서 PDF 콘텐츠를 인라인으로 표시할 수 있어 특히 효과적입니다. 또한 IronPDF의 HTML-PDF 변환 기능을 사용하여 필요에 따라 동적으로 PDF를 생성하여 볼 수도 있습니다.
WPF 및 WinForms 애플리케이션에 PDF 보기 기능을 통합할 수 있을까요?
네. WPF와 WinForms의 경우, WebView2 컨트롤을 호스트하고 저장된 PDF로 탐색하십시오; WebView2는 Microsoft Edge의 Chromium 엔진을 사용하며 자체 툴바, 줌 및 프린트를 포함합니다. WebView2는 더 이상 사용되지 않는 Internet Explorer 엔진에 의존했던 오래된 WebBrowser 컨트롤을 대체합니다. 브라우저 컨트롤을 호스트하지 않으려면 각 페이지를 이미지로 래스터화하고 이미지 또는 PictureBox에 표시하십시오. IronPDF는 또한 디지털 서명, 양식 작성 및 PDF 압축을 같은 문서에서 처리합니다.
시스템의 기본 PDF 뷰어를 .NET 애플리케이션에서 사용할 수 있습니까?
물론입니다. IronPDF는 System.Diagnostics.Process를 사용하여 시스템의 기본 PDF 뷰어와 통합을 지원합니다. 이 방식을 통해 사용자는 IronPDF를 사용하여 PDF 문서를 생성, 조작 또는 미리 준비하는 동시에 원하는 PDF 애플리케이션에서 PDF를 열 수 있습니다.
PDF 보기 기능 외에 어떤 추가 기능이 있나요?
IronPDF는 문서 보안을 위한 디지털 서명, 대화형 PDF를 위한 양식 작성 기능, 파일 크기를 줄이기 위한 PDF 압축, 동적 콘텐츠 생성을 위한 HTML에서 PDF 변환, 다양한 형식으로의 PDF 저장/내보내기를 포함한 광범위한 PDF 기능을 제공합니다.

