Title: Open a PDF file in C#
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);
}
Also at design time I added the file Test.pdf 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 appends the file name Test.pdf. It then makes the wbrPdf WebBrowser control navigate to that file.
Download the example to experiment with it and to see additional details.
|