How do I display a PDF in LiveCode?

There are occassions when you might want to be able to display a PDF document in your LiveCode 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

Launching a PDF in an external viewer

The simplest way to display a PDF from within LiveCode is to use the launch document command. This opens a document with the operating system's default program.

launch document "LiveCodeNotes-8_1_3.pdf"

Displaying a PDF within a LiveCode stack

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 browser widget to display PDFs within a stack.

To see how to do this we will create a new stack called "PDF Viewer", add a browser widget and a button that allows us to select the PDF file we want to view.

Selecting a PDF

We need to add code to 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.

on mouseUp
   local tFile
   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
      set the url of widget "browser" to tFile
   end if
end mouseUp  

Displaying the PDF

Displaying the PDF

Swith to Run mode and try selecting a PDF file.

0 Comments

Add your comment

E-Mail me when someone replies to this comment