Omnis Technical Note TNGI0021 December 2007

How to display PDF files directly in Omnis Studio

For Omnis Studio 3/4
By Götz Krija

Under Windows it is possible without any difficulties to display PDF files in an Omnis Studio window using the Acrobat PDF Reader control (ActiveX) provided by Adobe, which you can activate under External Components. Under Mac OS X, there is no equivalent of the ActiveX PDF Reader component, but you can simulate the PDF Reader using a combination of the Quicktime (Movieplayer) Omnis external, a Picture object, and a set of buttons - the result is not as slick as the 'real' PDF reader, but offers a reasonable alternative for Mac users.

For Windows

Under Windows, you can place an ActiveX PDF Reader object on a window, providing a button to prompt the user to select the PDF to be displayed. To load an ActiveX, right-click on the background of the Component Store and select the External Components option. Select the control you want from the ActiveX node in the tree list, in this case it's called "Adobe Acrobat 7.0 Browser Control". If the component is not in the list, click on the Browse button, navigate to your Common files folder, and locate the AcroPDF.dll file: C:\Program Files\Common Files\Adobe\Acrobat\ActiveX

External Components

Name the PDF component something like 'win_pdfviewer'. Then create a pushbutton and add the following code for selecting the PDF:

On evClick
Do FileOps.$getfilename(lPath,'Please select a PDF file','*.pdf')
Do $cwind.$objs.win_pdfviewer.$loadfile(lPath)
Do $cwind.$redraw()

The PDF component displays the PDF and provides all the controls in the standard Acrobat Reader application.

Win PDF viewer

For Mac OS X

For Mac OS X, it is not so straight forward. Create a window, drag a Movie Player control (Quicktime) into your window and set the properties $name to "Viewer" and $visible to kFalse. The Quicktime component will be used to load each page (or 'frame') in turn and transfer to an Omnis picture field.

Next drag a Picture object into your window, create an instance variable "iPicture" of the data type Picture and assign it to the $dataname property of the picture object. In addition create 4 buttons: the first button to open the PDF file, the others to step forward one page, step back a page, and one to return to the first page:

Code for Open PDF button:

On evClick
Do FileOps.$getfilename(lPath,'Please select a PDF file','*.pdf')
Do $cwind.$objs.Viewer.$moviefile.$assign(lPath)
; this loads the PDF in the movie player
Do $cwind.$objs.Viewer.$copyframe Returns iPicture
; loads the first frame or page into the picture field
Do $cwind.$redraw()

Code for buttons to browse forward, back, or go to front page (comment or uncomment as appropriate for each button):

On evClick
Do $cwind.$objs.Viewer.$stepforward() ;; forward 1 page
; Do $cwind.$objs.Viewer.$stepback() ;; back 1 page
; Do $cwind.$objs.Viewer.$gotofront() ;; go to first page
Do $cwind.$objs.Viewer.$copyframe Returns iPicture
Do $cwind.$redraw()

You could use both these techniques to create a window that allows the end-user to open and display a PDF on either Windows or Mac OS X platforms.

Mac PDF viewer

The following library contains a window that uses the two techniques on a page pane that displays the correct pane for either Windows or Mac.

Download the library here: