Tuesday, August 19, 2014

How to display PDF documents in Windows applications(C# and VB.Net)



To display PDF in Windows Application:
  1. Start a new Windows Project
  2. Right Click on the tool box and Click on “Choose Items”

  1. You will get the following “Choose Toolbox Items” window. Go to “COM Components” Tab  and check “Adobe PDF Reader” and click on “OK”

  1. You will now find the adobe control in the tool boxes.

  1. In the Design View Drag and drop Adobe PDF reader Control and a Button Control

On the button click event add the following code:

VB.Net code

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim dlg As OpenFileDialog
        dlg = New OpenFileDialog()
        dlg.Filter = "pdf files (*.pdf) |*.pdf;"
        dlg.ShowDialog()
        If (Not String.IsNullOrEmpty(dlg.FileName)) Then
            AxAcroPDF1.LoadFile(dlg.FileName)
        End If
     End Sub


C# .Net Code

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "pdf files (*.pdf) |*.pdf;";
            dlg.ShowDialog();
            if(dlg.FileName != null)
            {
                axAcroPDF1.LoadFile(dlg.FileName);
            }

        }

Output:





No comments:

Post a Comment