How to display PDF in form C#

By FoxLearn 7/12/2024 3:18:41 PM   128
To display a PDF within a Windows Forms application using C#, you can use the WebBrowser control, which is capable of rendering PDF files if Adobe Acrobat Reader or another PDF viewer plugin is installed on the user's machine.

Here's a step-by-step guide on How to display PDF in form C#

Open your Visual Studio, then create a new Windows Forms Application project.

Drag and drop the WebBrowser control onto your form. Resize and position it according to your layout needs.

display pdf in form c#

In your C# code, you can load a PDF file into the WebBrowser control using its Navigate method.

Double click on your form, then add a Form_Load event handler which allows you to display the pdf in a windows forms application.

private void Form1_Load(object sender, EventArgs e)
{
    // Replace this with the path to your PDF file
    string pdfFilePath = @"C:\Path\sample.pdf";

    // Load the PDF file into the WebBrowser control
    webBrowser1.Navigate(pdfFilePath);
}

The WebBrowser control relies on the system's default web browser or installed plugins to display PDF files. If the user's machine doesn’t have a PDF viewer installed, the control won’t be able to display the PDF.