Embed PDF into a VB.NET form using Adobe Reader Component

> Edraw Tip > Embed PDF into a VB.NET form using Adobe Reader Component
author
Posted by James Freeman |
PDF viewer component is an easy and reliable solution for developers to embed PDF into a VB.NET form using Adobe Reader Component.

What is the best way of embedding adobe pdf document in a VB.Net form with 100% compatibility? I believe most of you remember the good adobe reader component technology which allowed loading a pdf file in Visual Basic Windows form. But all these technologies do not support to do more limitation from modification pdf files.

The following article will show how to load pdf files in a VB.NET application step by step.

If you haven't the pdf viewer component, you need to install the package firstly.

How to display PDF Document in VB6 Application

Open the Visual Studio and create a new VB.NET application.

Right Click the Solution. Then click Add Reference... menu item.

VB.Net Add Reference

In the pop up dialog, choose the pdfviewer.ocx file from the Browse tab.

browse pdf viewer

Or choose the PDF Viewer Component from the COM tab.

Click OK. The PDF Viewer Component References have been added in the new vb.net project.

vb reference

Switch to the Form design window of Form1.

Switch to the Form design window

Drag the PDF Viewer Component from the Toolbox panel into the form1.

Add PDF Component

Type the following VB.NET codes to new, open, saveas, close and print a word document look like this:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadPDF.Click
With OpenFileDialog1
.DefaultExt = "pdf"
.Filter = "PDF File Formats (*.pdf)|*.pdf|All Files (*.*) | *.* ||"
.FilterIndex = 1
End With
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
AxPDFViewer1.LoadFile(OpenFileDialog1.FileName)
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub PDFInstalled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PDFInstalled.Click
If AxPDFViewer1.AdobeReaderIsInstalled = True Then
MsgBox("Ok. Your computer has installed the Adobe Reader", vbYesNo)
Else
MsgBox("Please installed the Adobe PDF Reader before using the component.", vbYesNo)
End If
End Sub

Private Sub ShowToolbars_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowToolbars.Click
If AxPDFViewer1.Titlebar = True Then
AxPDFViewer1.Titlebar = False
Else
AxPDFViewer1.Titlebar = True
End If
End Sub

Private Sub ShowScrollbar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowScrollbar.Click
If AxPDFViewer1.Scrollbar = True Then
AxPDFViewer1.Scrollbar = False
Else
AxPDFViewer1.Scrollbar = True
End If
End Sub

Private Sub ShowTitlebar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowTitlebar.Click
If AxPDFViewer1.Titlebar = True Then
AxPDFViewer1.Titlebar = False
Else
AxPDFViewer1.Titlebar = True
End If
End Sub

Private Sub CloseDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseDoc.Click
AxPDFViewer1.Clear()
End Sub

Private Sub AboutPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutPDF.Click
AxPDFViewer1.AboutPDFViewer()
End Sub

Private Sub First_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles First.Click
AxPDFViewer1.GotoFirstPage()
End Sub

Private Sub Prev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Prev.Click
AxPDFViewer1.GotoPreviousPage()
End Sub

Private Sub NextPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextPage.Click
AxPDFViewer1.GotoNextPage()
End Sub

Private Sub LastPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LastPage.Click
AxPDFViewer1.GotoLastPage()
End Sub

Private Sub PrintOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintOut.Click
AxPDFViewer1.PrintWithDialog()
End Sub

Private Sub DisableToolbarMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisableToolbarMenu.Click
AxPDFViewer1.DisableToolbarRightClickMenu(True)
End Sub

Private Sub DisableViewMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisableViewMenu.Click
AxPDFViewer1.DisableViewRightClickMenu(True)
End Sub

Private Sub DisableCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisableCopy.Click
AxPDFViewer1.DisableHotKeyCopy()
End Sub

Private Sub DisablePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisablePrint.Click
AxPDFViewer1.DisableHotKeyPrint()
End Sub

Private Sub DisableHotkeys_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisableHotkeys.Click
AxPDFViewer1.SetReadOnly()
AxPDFViewer1.DisableHotKeyCopy()
AxPDFViewer1.DisableHotKeyPrint()
AxPDFViewer1.DisableHotKeySave()
AxPDFViewer1.DisableHotKeySearch()
AxPDFViewer1.DisableHotKeyShowBookMarks()
AxPDFViewer1.DisableHotKeyShowThumnails()
AxPDFViewer1.DisableHotKeyShowToolbars()
End Sub
End Class

Open the Configuration Manager. Change the Active solution platform as x86 option.

x86 option.

Then build the VB.NET project and run.

PDF Component in VB.NET

The pdf reader component support adobe reader version 9, X and XI. It can run at the Windows 2000/Xp/Vista/2008/7/8/8.1 32 bit or 64 bit OS. To Embed pdf file into a VB.NET application, you needn't change anything, only call the LoadFile method:

public void Open()
{
axPDFViewer1.LoadFile(sPath);
axEDOffice1.Open("");'Open the standard file dialog
}

With a PDF viewer component, you are not only able to view PDF documents, but also able to disable print, disable copy, disable edit and change the pdf window options. Here is a VB.NET tutorial for displaying a PDF file in asp.net page or form. It uses the Adobe Reader software installed on system to render the pdf files. So it's 100% compatibility for all pdf files.

Relative Articles

download EdrawMind
main page

Get Started! You Will Love This Easy-To-Use Diagram Software

EdrawMax is an advanced all-in-one diagramming tool for creating professional flowcharts, org charts, mind maps, network diagrams, UML diagrams, floor plans, electrical diagrams, science illustrations, and more. Just try it, you will love it!