How do I display a PDF in Rev?
There are occassions when you might want to be able to display a PDF document in your Rev application, for example a help file. In this lesson we will look at a different ways you can do this.
Launching a PDF in an external viewer
Displaying a PDF within a Rev stack
But what if you don't want to display your PDF in a external window? You can use a revBrowser object to display PDFs within a stack.
To see how to do this we will create a new stack called "PDF Viewer", add an image area called "browser image" which will be used to define the area of the revBrowser object and a button that allows us to select the PDF file we want to view.
Initializing the revBrowser
Next we need to initialize the revBrowser object. Add the following to the card script. This will initialize the revBrowser object when the card is opened. In this case we do not pass a URL to the revBrowserOpen function so nothing is displayed yet.
-- We pass the windowId of the stack to revBrowser
-- so that it can determine which window to place the
-- browser object into
put the windowid of this stack into tWinID
-- Open the browser, using the windowId and initial url
put revBrowserOpen(tWinID,"") into sBrowserId
-- Set some basic properties for the browser
revBrowserSet sBrowserId, "showborder","true"
revBrowserSet sBrowserId, "rect",rect of image "browser image"
Selecting a PDF
Now lets script the "Browse" button so that the user can select a PDF to view. We use the answer file with type command to display only PDF files.
answer file "Please choose the file you would like to display" with type "PDF document|pdf|PDF"
if it is not empty then
put it into tFile
the browserSetURL handler is implemented in the card script
on browserSetURL pURL
## Set the url to be displayed to the given url
revBrowserSet sBrowserId, "url", pURL
You can do a lot more with revBrowser that we have discussed in this lesson, for more information have a look at the revBrowser functions and commands in the Dictionary.
For more examples of what you can do with revBrowser there is a Browser Sampler stack in the Resources/Examples folder of your Rev distribution.
You might also find the Explore LiveCode: The Internet tutorial interesting.