Embedded PDF Viewer Control


This article is about how to open PDF file in access using VBA code using ActiveX control.

We can embed PDF file using Adobe Acrobat PDF control reader. In this article we are embedding PDF control reader and we are place all the reader control on Microsoft Access form. So for this firstly we are insert a blank form from the toolbar as shown in fig 1.1.

Embedded PDF Viewer Control Fig-1.1

Fig:-1.1

Now select ActiveX control from designing toolbox as shown in Fig 1.2.

Embedded PDF Viewer Control Fig-1.2

Fig:-1.2

After click on ActiveX control a pop up will come and we have insert Adobe PDF reader control So this control will help me to read the PDF file as shown in Fig .1.3.

Embedded PDF Viewer Control Fig-1.3

Fig:-1.3

Now on the form design view we can see PDF reader control. And make the form more customized.

So client can view PDF document and can use control easily. So we have to add buttons and dropdowns as shown in Fig 1.4. And at the event procedures we have write appropriate VBA code to add functionality for these controls.

Embedded PDF Viewer Control Fig-1.4

Fig:-1.4

When we are giving the path of the PDF file then form will view look like as Fig 1.5 in Form View. And on right side of form there are different control listed below.

  1. Show Toolbar
  2. Show Scroll bars
  3. Zoom in and zoom out
  4. Page mode and layout mode
  5. View (Position)
  6. Move to first, previous, next, last page and you can also specify page number to move to that page
Embedded PDF Viewer Control Fig-1.5

Fig:-1.5

1. In form view when we are view the PDF file it will not show toolbar so we have to click on Show toolbar button and vice-versa, this will show toolbar on PDF file as shown like Fig 1.6

Embedded PDF Viewer Control Fig-1.6

Fig:-1.6

2. Next button is show scroll bar button on form so when we click on button then scroll bar will show on PDF file as shown in Fig 1.7 and if want hide this scroll bar we have to click again.

Embedded PDF Viewer Control Fig-1.7

Fig:-1.7

3. Next button is Zoom in, so according to need we can Zoom In the file as shown in Fig 1.8. We can use "CTRL +" Key also.

Embedded PDF Viewer Control Fig-1.8

Fig:-1.8

4. Similarly zoom out button, we can change then view according to need as shown in Fig 1.9. We can use "CTRL - "Key also.

Embedded PDF Viewer Control Fig-1.9

Fig:-1.9

5. Next button is page mode, so we can change page mode according to need. In the dropdown we have three modes bookmarks, thumb, none as shown in Fig 2.1.

Embedded PDF Viewer Control Fig-2.1

Fig:-2.1

6. Next button is layout mode. In the dropdown we have following modes:-

  1. DontCare
  2. SinglePage
  3. OneColumn
  4. TwoColumnLeft
  5. TwoColumnRight

So we can choose any mode according to need as shown in Fig 2.2.

Embedded PDF Viewer Control Fig-2.2

Fig:-2.2

7. Next button is view. In the dropdown we have following view modes as follow:-

  • Fit (Both horizontal and vertical)
  • FitH (Fit Horizontal)
  • FitV (Fit Vertical)
  • FitB (Fit within Bounding Box both horizontally and vertically)
  • FitBH (Fit within Bounding Box horizontally)
  • FitBV (Fit within Bounding Box vertically)

So we can choose any mode according to need as shown in Fig 2.3.

Embedded PDF Viewer Control Fig-2.3

Fig:-2.3

8. Next button is "Go to page" button as shown in Fig 2.4 .So we have just put the number inside text box and click on button then control will automatically go on that particular page.

Embedded PDF Viewer Control Fig-2.4

Fig:-2.4

9. These are bound controls as shown in Fig 2.5 .Button listed below:-

  1. First
  2. Previous
  3. Next
  4. Last

So according to need when want move make use of these button we can easily.

Embedded PDF Viewer Control Fig-2.5

Fig:-2.5

Complete VBA code for the procedure is given here: -

Dim ZoomFactor As Double

Private Sub cboLayoutMode_AfterUpdate()
AcroPDF0.setLayoutMode (cboLayoutMode)
End Sub

Private Sub cboPageMode_AfterUpdate()
AcroPDF0.setPageMode (cboPageMode)
End Sub

Private Sub cboView_AfterUpdate()
AcroPDF0.setView (cboView)
End Sub

Private Sub cmdFirst_Click()
AcroPDF0.gotoFirstPage
End Sub

Private Sub cmdGoToPage_Click()
AcroPDF0.setCurrentPage (CInt(txtPage))
End Sub

Private Sub cmdLast_Click()
AcroPDF0.gotoLastPage
End Sub

Private Sub cmdNext_Click()
AcroPDF0.gotoNextPage
End Sub

Private Sub cmdPrevious_Click()
AcroPDF0.gotoPreviousPage
End Sub

Private Sub cmdShowScrollBars_Click()
If cmdShowScrollBars Then
AcroPDF0.setShowScrollbars (True)
cmdShowScrollBars.Caption = "Hide Scroll Bars"
Else
AcroPDF0.setShowScrollbars (False)
cmdShowScrollBars.Caption = "Show Scroll Bars"
End If
End Sub

Private Sub cmdShowToolBar_Click()
If cmdShowToolBar Then
AcroPDF0.setShowToolbar (True)
Me.cmdShowToolBar.Caption = "Hide ToolBar"
Else
AcroPDF0.setShowToolbar (False)
Me.cmdShowToolBar.Caption = "Show ToolBar"
End If
End Sub

Private Sub cmdZoomIn_Click()
ZoomFactor = ZoomFactor + 100
AcroPDF0.setZoom (ZoomFactor)
End Sub

Private Sub cmdZoomOut_Click()
If ZoomFactor <= 100 Then
ZoomFactor = 100
Else
ZoomFactor = ZoomFactor - 100
End If
AcroPDF0.setZoom (ZoomFactor)
End Sub


DISCLAIMER

It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. ERP Makers will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.


 

BUY SERVICES CONTACT