푸터 콘텐츠로 바로가기
IRONPDF 사용

How to Open PDFs in Default Viewer in C#

Opening a PDF in the default viewer is a common task. You’ll often need this when generating PDFs in a .NET application. After creating and editing PDF files programmatically with IronPDF, you often need to display them to users immediately in their chosen default application (such as Adobe Acrobat or Microsoft Edge). This guide will walk you through the steps on how to generate PDF files using IronPDF and how they can be automatically opened in Windows using System.Diagnostics.Process.Start.

The combination of IronPDF’s powerful HTML-to-PDF conversion capabilities with the simple Process launch method creates a seamless workflow for creating and displaying professional PDF files in your default apps settings.

How do you generate and open a PDF File with IronPDF?

The most straightforward approach involves three steps:

  1. Create a PDF document with IronPDF.
  2. Save the file to a directory.
  3. Open the PDF in the user’s default app.

Here’s a complete working example you can try in Visual Studio with a new Console App project:

using IronPdf;
using System.Diagnostics;
// Create a new PDF renderer
var renderer = new ChromePdfRenderer();
// Generate PDF from HTML content
var pdf = renderer.RenderHtmlAsPdf(@"
    <html>
        <body>
            <h1>Invoice #12345</h1>
            <p>Generated on: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>
            <table>
                <tr><td>Product</td><td>Price</td></tr>
                <tr><td>IronPDF License</td><td>$799</td></tr>
            </table>
        </body>
    </html>");
// Save the PDF to a file
string outputPath = "invoice.pdf";
pdf.SaveAs(outputPath);
// Open the PDF in the default viewer
Process.Start(new ProcessStartInfo
{
    FileName = outputPath,
    UseShellExecute = true
});
using IronPdf;
using System.Diagnostics;
// Create a new PDF renderer
var renderer = new ChromePdfRenderer();
// Generate PDF from HTML content
var pdf = renderer.RenderHtmlAsPdf(@"
    <html>
        <body>
            <h1>Invoice #12345</h1>
            <p>Generated on: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>
            <table>
                <tr><td>Product</td><td>Price</td></tr>
                <tr><td>IronPDF License</td><td>$799</td></tr>
            </table>
        </body>
    </html>");
// Save the PDF to a file
string outputPath = "invoice.pdf";
pdf.SaveAs(outputPath);
// Open the PDF in the default viewer
Process.Start(new ProcessStartInfo
{
    FileName = outputPath,
    UseShellExecute = true
});
$vbLabelText   $csharpLabel

This code first creates a ChromePdfRenderer instance, which is IronPDF's primary class for converting HTML to PDF. The RenderHtmlAsPdf method converts the HTML string into a PDF document object.

After saving the PDF using SaveAs, the code uses Process.Start with ProcessStartInfo to open the file in the default PDF viewer. The key setting here is UseShellExecute = true, which tells Windows to open the PDF file with its default application.

Output

As you can see in the image below, IronPDF was able to successfully generate the PDF file and display it using the default viewer. You'll notice in my case, this is Opera GX.

How to Open PDFs in Default Viewer in C#: Figure 1 - PDF displayed using default viewer

Why does UseShellExecute matter when opening PDF documents?

In .NET Core and modern .NET versions, the UseShellExecute parameter defaults to false. Without explicitly setting it to true, your app will throw an error when trying to launch a PDF.

using IronPdf;
using System.Diagnostics;
using System.IO;
// Generate a report with IronPDF
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;
var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Save to temp directory for immediate viewing
string tempPath = Path.Combine(Path.GetTempPath(), $"URL_{Guid.NewGuid()}.pdf");
pdf.SaveAs(tempPath);
// IMPORTANT: Set UseShellExecute = true for .NET Core/5+
var startInfo = new ProcessStartInfo
{
    FileName = tempPath,
    UseShellExecute = true  // Required in .NET Core/5+ to open PDF in default viewer
};
Process.Start(startInfo);
using IronPdf;
using System.Diagnostics;
using System.IO;
// Generate a report with IronPDF
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;
var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Save to temp directory for immediate viewing
string tempPath = Path.Combine(Path.GetTempPath(), $"URL_{Guid.NewGuid()}.pdf");
pdf.SaveAs(tempPath);
// IMPORTANT: Set UseShellExecute = true for .NET Core/5+
var startInfo = new ProcessStartInfo
{
    FileName = tempPath,
    UseShellExecute = true  // Required in .NET Core/5+ to open PDF in default viewer
};
Process.Start(startInfo);
$vbLabelText   $csharpLabel

The UseShellExecute property determines whether to use the operating system shell to start the process. When set to true, Windows uses the file association registry to determine which default PDF reader should open the file. Without this setting in modern .NET versions, you'll encounter an error stating the file cannot be opened. Using a temporary directory with a unique filename (via Guid.NewGuid()) prevents file conflicts when generating multiple PDFs. For more details on rendering URLs to PDF, see IronPDF's documentation.

Output

How to Open PDFs in Default Viewer in C#: Figure 2 - URL to PDF generated and displayed using default viewer

How do you handle file paths correctly?

File paths with spaces and special characters require proper handling. Here's a robust approach that includes error checking:

using IronPdf;
using System.Diagnostics;
using System.IO;
// Generate PDF from HTML file
var renderer = new ChromePdfRenderer();
var htmlContent = File.ReadAllText("template.html");
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Create output directory if it doesn't exist
string outputDir = @"C:\PDF Reports\Monthly";
Directory.CreateDirectory(outputDir);
// Build file path with timestamp
string fileName = $"Report_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
string fullPath = Path.Combine(outputDir, fileName);
// Save the PDF
pdf.SaveAs(fullPath);
// Verify file exists before opening in default PDF viewer
if (File.Exists(fullPath))
{
    Process.Start(new ProcessStartInfo
    {
        FileName = fullPath,
        UseShellExecute = true
    });
}
else
{
    Console.WriteLine($"Error: PDF file not found at {fullPath}");
}
using IronPdf;
using System.Diagnostics;
using System.IO;
// Generate PDF from HTML file
var renderer = new ChromePdfRenderer();
var htmlContent = File.ReadAllText("template.html");
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Create output directory if it doesn't exist
string outputDir = @"C:\PDF Reports\Monthly";
Directory.CreateDirectory(outputDir);
// Build file path with timestamp
string fileName = $"Report_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
string fullPath = Path.Combine(outputDir, fileName);
// Save the PDF
pdf.SaveAs(fullPath);
// Verify file exists before opening in default PDF viewer
if (File.Exists(fullPath))
{
    Process.Start(new ProcessStartInfo
    {
        FileName = fullPath,
        UseShellExecute = true
    });
}
else
{
    Console.WriteLine($"Error: PDF file not found at {fullPath}");
}
$vbLabelText   $csharpLabel

This code shows several best practices: using Path.Combine to build file paths correctly regardless of the operating system, creating directories as needed with Directory.CreateDirectory, and verifying file existence before attempting to open the PDF in the default viewer.

The timestamp in the filename ensures uniqueness and provides a clear record of when each PDF was generated. For more advanced PDF manipulation options, explore IronPDF's editing capabilities.

What are the best practices for opening generated PDFs?

For production applications, consider implementing a more complete workflow that handles the PDF lifecycle correctly:

using IronPdf;
using IronPdf.Rendering;
using System.Diagnostics;
using System.IO;
public static void GenerateAndDisplayPdf(string htmlContent, string documentName)
{
    try
    {
        // Configure IronPDF renderer with production settings
        var renderer = new ChromePdfRenderer
        {
            RenderingOptions = new ChromePdfRenderOptions
            {
                PaperSize =PdfPaperSize.A4,
                PrintHtmlBackgrounds = true,
                CreatePdfFormsFromHtml = true
            }
        };
        // Generate the PDF
        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        // Use user's Documents folder for better accessibility
        string documentsPath = Environment.GetFolderPath(
            Environment.SpecialFolder.MyDocuments);
        string pdfFolder = Path.Combine(documentsPath, "Generated PDFs");
        Directory.CreateDirectory(pdfFolder);
        string outputPath = Path.Combine(pdfFolder, $"{documentName}.pdf");
        pdf.SaveAs(outputPath);
        // Open PDF in default viewer and don't wait for it to close
        var process = Process.Start(new ProcessStartInfo
        {
            FileName = outputPath,
            UseShellExecute = true  // Essential for opening PDF in default application
        });
        Console.WriteLine($"PDF opened: {outputPath}");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error generating or opening PDF: {ex.Message}");
    }
}
using IronPdf;
using IronPdf.Rendering;
using System.Diagnostics;
using System.IO;
public static void GenerateAndDisplayPdf(string htmlContent, string documentName)
{
    try
    {
        // Configure IronPDF renderer with production settings
        var renderer = new ChromePdfRenderer
        {
            RenderingOptions = new ChromePdfRenderOptions
            {
                PaperSize =PdfPaperSize.A4,
                PrintHtmlBackgrounds = true,
                CreatePdfFormsFromHtml = true
            }
        };
        // Generate the PDF
        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        // Use user's Documents folder for better accessibility
        string documentsPath = Environment.GetFolderPath(
            Environment.SpecialFolder.MyDocuments);
        string pdfFolder = Path.Combine(documentsPath, "Generated PDFs");
        Directory.CreateDirectory(pdfFolder);
        string outputPath = Path.Combine(pdfFolder, $"{documentName}.pdf");
        pdf.SaveAs(outputPath);
        // Open PDF in default viewer and don't wait for it to close
        var process = Process.Start(new ProcessStartInfo
        {
            FileName = outputPath,
            UseShellExecute = true  // Essential for opening PDF in default application
        });
        Console.WriteLine($"PDF opened: {outputPath}");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error generating or opening PDF: {ex.Message}");
    }
}
$vbLabelText   $csharpLabel

This example includes error handling and saves PDFs in the user’s Documents folder, which works better in real-world apps. It also configures IronPDF with appropriate rendering options to give your PDF documents a truly customized feel when you render them.

The method doesn't wait for the PDF viewer to close, allowing your application to continue running while the user views the document, according to Microsoft's documentation on Process.Start, this approach ensures proper resource management.

How to Open PDFs in Default Viewer in C#: Figure 3 - PDF generation to viewing Process workflow

Conclusion

Opening a PDF file in the default application from a .NET program is easy with IronPDF and System.Diagnostics.Process. By setting the correct parameters (UseShellExecute = true) and providing a valid path, your .NET project will successfully launch the PDF in the default PDF reader.

Whether you’re working in Visual Studio, building a Windows desktop exe, or experimenting with a web app, this approach works consistently. IronPDF handles PDF creation, while Windows handles preview and display through the default app installed on the computer.

참고해 주세요Note: If no PDF viewer is installed, Windows may show a dialog asking you to select or download one.

This tutorial provides a comprehensive solution and code for managing PDF files in your .NET applications, covering creation and viewing without the need for additional software or dependencies beyond IronPDF and the standard Microsoft .NET runtime.

Ready to implement PDF generation and viewing in your application? Start with a free trial to find the perfect fit for your needs.

자주 묻는 질문

C#을 사용하여 기본 뷰어에서 PDF를 열려면 어떻게 해야 하나요?

C#의 기본 뷰어에서 PDF를 열려면 IronPDF를 사용하여 PDF를 생성하고 System.Diagnostics.Process.Start를 사용하여 사용자의 기본 PDF 애플리케이션에서 PDF를 열 수 있습니다.

IronPDF란 무엇인가요?

IronPDF는 개발자가 애플리케이션 내에서 프로그래밍 방식으로 PDF 파일을 생성, 편집 및 조작할 수 있는 .NET 라이브러리입니다.

IronPDF를 사용하기 위한 시스템 요구 사항은 무엇인가요?

IronPDF는 모든 .NET 애플리케이션과 호환되며 Windows, macOS 및 Linux 플랫폼에서 작동합니다. .NET Framework 또는 .NET Core/5+가 설치되어 있어야 합니다.

IronPDF는 기본적으로 Adobe Acrobat에서 PDF를 열 수 있나요?

예, IronPDF는 사용자가 설정한 기본 PDF 뷰어에서 열리는 PDF를 생성할 수 있으며, 이는 Adobe Acrobat, Microsoft Edge 또는 기타 PDF 보기 애플리케이션이 될 수 있습니다.

시스템.진단.프로세스.시작은 IronPDF와 어떻게 작동하나요?

기본 뷰어에서 생성된 PDF 파일을 열려면 System.Diagnostics.Process.Start를 사용합니다. IronPDF가 파일을 생성하면 이 메서드는 PDF 파일과 연결된 기본 애플리케이션을 실행하여 파일을 표시합니다.

IronPDF로 PDF 파일을 편집할 수 있나요?

예, IronPDF를 사용하면 기존 PDF 파일을 저장하거나 표시하기 전에 텍스트, 이미지, 주석 등을 추가하여 편집할 수 있습니다.

IronPDF는 어떤 프로그래밍 언어를 지원하나요?

IronPDF는 주로 C#과 함께 사용되지만 VB.NET 및 기타 .NET 지원 언어를 사용하는 프로젝트에도 통합할 수 있습니다.

IronPDF는 생성 후 PDF 표시를 자동화할 수 있나요?

예, IronPDF로 PDF를 생성한 후 System.Diagnostics.Process.Start를 사용하여 사용자의 기본 뷰어에서 즉시 열도록 표시를 자동화할 수 있습니다.

IronPDF를 사용하는 데 사용할 수 있는 코드 예제가 있나요?

IronPDF 문서는 C#을 사용하여 기본 뷰어에서 PDF를 여는 방법을 비롯하여 PDF를 생성하고 조작하기 위한 다양한 코드 예제를 제공합니다.

IronPDF의 일반적인 사용 사례는 무엇인가요?

IronPDF의 일반적인 사용 사례로는 보고서, 송장 및 기타 문서 생성, HTML을 PDF로 변환, .NET 애플리케이션에서 PDF 표시 프로세스 자동화 등이 있습니다.

IronPDF는 .NET 10과 호환되며 이로 인해 어떤 이점이 있나요?

예. IronPDF는 런타임 및 언어 개선 사항을 포함하여 .NET 10과 완벽하게 호환됩니다. .NET 10과 함께 IronPDF를 사용하면 힙 할당 감소, 빠른 PDF 생성, 최신 API 및 플랫폼과의 원활한 통합과 같은 성능 개선의 이점을 애플리케이션에서 누릴 수 있습니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.