Open document

Just starting out? Need help? Post your questions and find answers here.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Open document

Post by Polo »

Hi,

I want my program to open a PDF document, using the default program available on the OS.
I'm unsure on how to do that, with cross platform in mind.
Anybody has an idea?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Open document

Post by ts-soft »

Code: Select all

RunProgram("mypdf.pdf")
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Open document

Post by Polo »

ts-soft wrote:

Code: Select all

RunProgram("mypdf.pdf")
Thanks, but it doesn't work (at least not on OSX).
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Open document

Post by jesperbrannmark »

Try this

Code: Select all

CompilerIf #PB_Compiler_OS=#PB_OS_MacOS
  a.s="tell application "+Chr(34)+"Preview"+Chr(34)+#LF$
  a.s+"activate"+#LF$
  a.s+"open "+Chr(34)+"/absolute/path/To/file/my file.pdf"+Chr(34)+#LF$
  a.s+"End tell"+#LF$
  COCOA_AppleScript(a.s)
CompilerEndIf
Take advantage of applescript.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Open document

Post by Polo »

Thanks, how do I use CocoaScript with PB?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Open document

Post by Polo »

Found the solution for OSX, if that can help somebody :)

RunProgram("open", doc.pdf, "", #PB_Program_Open)
Post Reply