How to Open a PDF File in VB

Written by jeffrey abbott
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Open a PDF File in VB
Binary code (Jupiterimages/Photos.com/Getty Images)

Do you need to open a PDF file from a program you're writing in Visual Basic? You can open almost any type of file from within a VB program as long as you know the correct code sequence. One way of opening a file is by coding the open process to a button that the user can click. There are many different ways to open a PDF file, but the basic code will work in many of those cases.

Skill level:
Moderately Easy

Other People Are Reading

Things you need

  • Windows computer with a Visual Basic compiler

Show MoreHide

Instructions

    From Default Viewer

  1. 1

    Create a Private Sub button event to handle the PDF file by using the following code example:

    "Private Sub ButtonOpen(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpen.Click

    End Sub"

  2. 2

    Use the Process.Start method to open the PDF with the default PDF viewer. For example, use the following code to open "book.pdf" located in the Documents folder:

    "Process.Start("C:\Documents\book.pdf")", but use a valid location for your PDF file. Place this code before the "End Sub" section.

  3. 3

    Compile the code and test the results. The button click event opens the PDF file you specified.

    From Default Browser

  1. 1

    Create a Private Sub button event to handle the PDF file by using the following code example:

    "Private Sub ButtonOpen(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpen.Click

    End Sub"

  2. 2

    Use the WebBrowser.Navigate method to open the PDF with the default Web browser. For example, type the following code before the "End Sub" section:

    "WebBrowser.Navigate("C:\Documents\book.pdf")", but use a valid location for your PDF file.

  3. 3

    Compile the code and test the results. The button click event opens the PDF file you specified.

    With a Specific Program

  1. 1

    Create a Private Sub button event to handle Adobe Reader by using the following code example:

    "Private Sub ButtonOpen(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpen.Click

    End Sub"

  2. 2

    Add the "Adobe PDF Reader" control from your toolbox to the form you are using. Find the AdobeReader.src property and change it to "AdobeReader.src = "C:\Documents\book.pdf"" but use a valid location for your PDF file.

  3. 3

    Compile the code and test the results. The button click event opens the PDF file you specified within the application window.

Tips and warnings

  • Before starting this workflow, it is important to have a basic understanding of VB.
  • You'll need access to a VB compiler to make this code compile and run.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.