I need a button that can open a PDF file

Hi All I want to use blender GE to make a restaurants guide for Melbourne. For my work I can do everything I need to do except I need a button that can open a PDF file with a restaurant’s menu or something like a hyperlink to the file. So the file will open up in the PDF reader when I click on the button. How do I do it?’

I try to look in to it and found.

import os
import subprocess

pdf = “path/to/pdf”
acrobatPath = r’C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe’
subprocess.Popen("%s %s" % (acrobatPath, pdf))

but I don’t know what to do with it or if its right and what is os.system(path)?
Thanks for any help :slight_smile:

I am on Win 7 64bit

Hi duckford u can try something like this:

import bge as ge
import os

#show mouse

#get the controller
cont = ge.logic.getCurrentController()

obj = cont.owner

sens = cont.sensors['space']

if sens.positive:
    #any file should do"
    path = "C:\\foto.jpg" #dont use single slash here
    #fix windows paths with spaces
    path = path.replace("\\", "\\\\")
    if os.path.exists(path):
        import subprocess

        system = os.name
        if system=="posix":
            subprocess.Popen(["xdg-open", path])
        elif system=="nt":
            subprocess.Popen([path], shell=True)
            subprocess.Popen(["open "+path])

Note that you dont need to specify your .exe file. This will open your file with the associated application.

If you need to specify the .exe use:
subprocess.Popen([binarypath, pdfpath])
you can try relative routes but again, use double slash instead single like: (only for windows)
bin = “\acrobat.exe”
bin = “C:\my folder\acrobat.exe”
bin = “C:\my folder\acrobat.exe”
bin = bin.replace("\", “\\”)