Software tips, techniques, and news.

By Weihao Ding  Posted on  March 3rd, 2015  in  Free Downloads, FileMaker

Interactive PDFs in FileMaker Go

Interactive containers were introduced in FileMaker 12 to enable users to view the content of PDFs, audit files and video files directly in FileMaker Pro. A common use case for interactive containers is to use them to scroll through pages of a PDF, zoom in and out, and copy text, all without having to leave FileMaker Pro.

The problem, however, is that interactive containers aren’t fully supported in FileMaker Go. For example, PDFs only show their first page and to view the full content the user will have to tap on the container field and choose “View” to open up the PDF file in a PDF reader app.


FileMaker Go

In some use cases, the user may want to be able to do data entry and view the content of a PDF file at the same time. In FileMaker Go they will have to switch back and forth which could harm the usability and user experience. One workaround for this problem is to display the PDF in a web viewer instead of a container field. This can be done natively in FileMaker Go.

Web Viewer + File URL = Interactive PDF

Web viewer, as a browser inside FileMaker, not only can show web pages, but it can show files on your device as well. Hence, we can display PDFs on our devices in a web viewer. The URL we use to retrieve the PDF file is called File URL

File URL usually takes the form of

file://host/path

If file resides on a different machine, you should specify the fully qualified domain name as host. Otherwise you can omit the host part and it is taken to be “localhost”.

Path is the directory path to the file you want to retrieve. It takes the form of directory/directory/…/file_name.

As an example, let’s say I want to retrieve a txt file named “foo.txt” stored in folder folder1/folder2/ on my device. Since the file is local, I would omit the host part. Path would be folder1/folder2/foo.txt. Put them together, the file URL is “file:///folder1/folder2/foo.txt”.

Note that I used three “/“ in between “file:” and “folder1/…”. The reason is, technically speaking, when host is omitted, you should keep the “/“ after it. However many interpreters can handle situations where the third “/“ got omitted together with the host. On the iPad we can use either form. Both “file:///folder1/folder2/foo.txt” (three slashes) and “file://folder1/folder2/foo.txt” (two slashes) are recognizable on iPad.

So in order to display the PDF in a web viewer, all we need to do is to export the PDF and use the path to the exported file as a file URL in the web viewer.

FileMaker Go

A Step-by-Step Example

1. Since we will display the PDF in a web viewer, you will need to add a web viewer to your layout. Double click the web viewer in Layout mode to set the Web Address for the web viewer to be a global variable that’s going to store the file URL.

2. Then you need to name your web viewer using the inspector.

FileMaker Go

3. Build a script to export the PDF file and display it in web viewer. Here is an example:

#PURPOSE: To export PDF file to temp folder and set web viewer
#Start, End Context: Sample File, Sample File
#2015-02-16, WD, Created script.
#
#
#----------INITIALIZE-----------
Allow User Abort [ Off ]
Set Error Capture [ On ]
Freeze Window
#
#
#----------HANDLE UI ERRORS-----------
Perform Script [ "UI - Halt If Not in Browse Mode" ]
Perform Script [ "UI - Halt If No Records in Found Set" ]
Perform Script [ "UI - Commit Record and Halt If Invalid" ]
#
#
#----------POPULATE PARAMETERS, VARIABLES, CONSTANTS-----------
#Constants
Set Variable [ $TASK_NAME; Value:"View PDF in Web Viewer" ]
Set Variable [ $ERROR_MSG_SUMMARY; Value:"Unable to view field PDF in web viewer. " ]
Set Variable [ $CONTAINER_PDF; Value:"CONTAINER: PDF" ]
Set Variable [ $WEB_VIEWER_PDF; Value:"WEB VIEWER: PDF" ]
#
#
#----------MAKE SURE THERE IS A PDF TO VIEW-----------
If [ IsEmpty ( Sample File::pdf ) ]
    Show Custom Dialog [ Title: "Sorry"; Message: $ERROR_MSG_SUMMARY & "There is no PDF to view. Please insert
     a PDF file to the container field."; Default Button: "OK", Commit: "Yes" ]
    Go to Object [  ]
    Insert PDF [  ]
    Exit Script [ Result: 0 ]
End If
#
#
#----------EXPORT PDF TO TEMP FOLDER-----------
#Copy pdf to temp container
Set Field [ Sample File::zgcTempExport; Sample File::pdf ]
#Grab temp path
Set Variable [ $filePath; Value:Get( TemporaryPath ) & GetContainerAttribute( Sample File::zgcTempExport ; 
"filename" ) ]
#Generate FM file path
Set Variable [ $filePathFM; Value:"filemac:" & $filePath ]
#Export to temp path
Export Field Contents [ Sample File::zgcTempExport; "$filePathFM" ]
#Error trap export
Set Variable [ $lastError; Value:Get( LastError ) ]
If [ $lastError ≠ 0 ]
    Go to Layout [ original layout ]
    Show Custom Dialog [ Title: $TASK_NAME; Message: $ERROR_MSG_SUMMARY & 
    "Could not export PDF to temp folder." & "¶¶" &
"ERROR: " & fmErrorMessage( $lastError ); Default Button: "OK", Commit: "Yes" ]
    Exit Script [ Result: 0 ]
End If
#Generate file URL
Set Variable [ $$fileURL; Value:"file:/" & $filePath ]
#
#
#----------SET WEB VIEWER-----------
#Go to target layout
Go to Layout [ "Example" ]
#Set web viewer
Set Web Viewer [ Object Name: $WEB_VIEWER_PDF; Action: Reset ]
Go to Object [ Object Name: $WEB_VIEWER_PDF ]
#
#
#----------WRAP UP-----------
Exit Script [ Result: 1 ]Example Script Breakdown
  1. Copy the PDF to a temporary container field. In our example, Sample File::pdf is where the PDF stored. Sample File::zgcTempExport is a global container field created to temporarily store the PDF that needs to be exported. By doing this we can make this script more generic. If you have multiple sources to display you can simply change this step without having to change the whole script.
  #Copy pdf to temp container Set Field [ Sample File::zgcTempExport; Sample File::pdf ]
  1. Grab temp path. We will export the PDF to iPad’s temporary path since we don’t actually want to expose the exported file to the user and want it to be automatically cleaned out at some point after use.
 #Grab temp path Set Variable [ $filePath; Value:Get( TemporaryPath ) & GetContainerAttribute ( Sample File::zgcTempExport ; "filename" ) ]
  1. Generate the FileMaker file path by adding prefix “filemac:” in front of your file path.
 #Generate FM file path Set Variable [ $filePathFM; Value:"filemac:" & $filePath ]
  1. Export to temp path. Use “Export Field Contents” script step to export the PDF file to the path stored in variable.
 #Export to temp path Export 
 Field Contents [ Sample File::zgcTempExport; “$filePathFM” ] 
 #
 #Error trap export 
 Set Variable [ $lastError; Value:Get( LastError ) ] 
 If [ $lastError ≠ 0 ] 
     Go to Layout [ original layout ] 
     Show Custom Dialog [ Title: $TASK_NAME; Message: $ERROR_MSG_SUMMARY & "Could not export PDF to temp folder." & "¶¶" & "ERROR: " & fmErrorMessage( $lastError ); Default Button: “OK”, Commit: “Yes” ] 
     Exit Script [ Result: 0 ]
 End If
  1. Generate file URL. In this step we added the prefix “file:/“ in front of $filePath to get a file URL. Note that I only add one “/“ here. Together with the ‘/“ returned at the beginning of Get ( TemporaryPath ) that give us two “/“ in total, regardless of whether the host name is omitted or not. I did this to increase portability. Using “file://“ (double slashes) is fine on iOS and Windows, but not on Mac OS. “file:/“ (single slash) works on all three platforms.
 #Generate file URL Set Variable [ $$fileURL; Value:"file:/" & $filePath ]
  1. Go to target layout and set web viewer. These two steps are just to make sure the web viewer will refresh and show the PDF properly. This script could be either added to a script trigger or bound to a button. Be sure to download our Interactive PDFs in FileMaker Go Sample file to get a better understanding of how this work.
 #Go to target layout
 Go to Layout [ “Example” ]
 #
 #Set web viewer
 Set Web Viewer [ Object Name: $WEB_VIEWER_PDF; Action: Reset ]
 Go to Object [ Object Name: $WEB_VIEWER_PDF ]

Conclusion

By combining web viewers and file URLs you can show the contents of a PDF in FileMaker Go that works in a similar way as interactive containers in FileMaker Pro. This will expand the use cases for FileMaker Go solutions and enhance the usability when users need to do data entry and view the content of a PDF at the same time.

Did you know we are an authorized reseller for FileMaker Licensing?
Contact us to discuss upgrading your FileMaker software.

Download
Download the Interactive PDFs in FileMaker Go File
Please complete the form below to download your FREE FileMaker file.
FileMaker Experience *
Terms of Use *
OPT-IN: I agree that I am downloading a completely free FileMaker application file with no strings attached. This file is unlocked, and I may use it for my business or organization as I see fit. Because I am downloading a free file, I agree that I should receive occasional marketing. I understand that I can OPT-OUT of these emails at anytime.
Weihao Ding thumbnail
Weihao Ding

Weihao is a FileMaker Certified Developer, a creative thinker and a great communicator. He thrives on utilizing his keen technical skillset to solve problems in a manner that will make a positive difference for customers. His passion and drive to demonstrate excellence is evident in all of his work.

FileMaker 18 Certified Developer
FileMaker 17 Certified Developer
FileMaker 16 Certified Developer
FileMaker 15 Certified Developer
FileMaker 14 Certified Developer
FileMaker 13 Certified Developer
FileMaker 12 Certified Developer
FileMaker 11 Certified Developer
"We were actually able to add more features than we thought would be possible within our budget. We always experienced a ‘can do’ attitude and DB Services was incredibly patient and easy to work with."
Courtney Hartman
Art Director
"The new FileMaker custom website interface is very user-friendly and easy to follow for our clients. In addition, it is much faster than the old Instant Web Publishing (IWP) interface. Thank you and all the others who have helped us out at DB Services. I am very grateful for the excellent service you provide us. Its nice to know we can call you for help if we have an issue."
Wayne Capek
President
"We needed a solution that would simplify the administration of our responsibilities under our contract with the State of Indiana. We have seen a dramatic increase across the state in the number of potential foster and adoptive parents that have begun the preparation and training process. This increase has resulted in a significant opportunity for children available for adoption. That’s a big win for everyone! And it’s all because we can refer potential parents to the proper state contacts efficiently and quickly."
Chris Morrison
Executive Director
"Thank you for all of your expertise and valuable help. I am so grateful to have found DB Services."
Linda Findlay
Owner
"Thank you for our new database system. We transitioned from a carbon copy paper based system to a digital database. The software has saved us time and money. We used to archive all our jobs in cabinets, now we can look up a job in seconds from anywhere. The software allows us to easily email estimates to our customers in pdf format. In a year there was a return on investment just from eliminating the purchasing of our carbon forms."
Todd Cartmel
Owner
"The new system allows us to create and track jobs for customers along with inventory, something we had been doing with separate word and spreadsheet files. Because it’s now so intuitive, new staff members are able to begin using the database immediately without our usual training session and ‘cheat sheets’ for getting around within the file."
Tom Andrews
President