Open a PDF file in C#


[Open a PDF file]

At design time I added a WebBrowser control to the form. When the program starts it uses the following code to open a PDF file in a WebBrowser control.

// Display the PDF file.
private void Form1_Load(object sender, EventArgs e)
{
    string filename = Application.StartupPath;
    filename = Path.GetFullPath(
        Path.Combine(filename, ".\\Test.pdf"));
    wbrPdf.Navigate(filename);
}

At design time I added that file to the project and set its “Copy to Output Directory” property to “Copy if newer” so the file will be in the executable program’s directory.

This code gets the program’s startup directory and adds the file name Test.pdf. It then makes the wbrPdf WebBrowser control navigate to that file.


Download Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in controls and tagged , , , , , , , , . Bookmark the permalink.

2 Responses to Open a PDF file in C#

  1. Richard Payne says:

    I have created a PDF from word document and wish to know how to jump to header after opening the webrowser

Leave a Reply

Your email address will not be published. Required fields are marked *