Open pdf file


#1

I have help for my app in .pdf format.

On Windows I can use ShellExecute to open it.

What can I do on Linux and on OSX to open and show this pdf?


#2

Open on Mac OS X ( https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/open.1.html ) can do that (with juce::ChildProcess)?


#3

You could probably use File::startAsProcess(), if I understand you correctly. 


#4

Oops, i forgot that one :wink:


#5

This is what I use now and it works:


juce::String fileName;
#if JUCE_WINDOWS
    fileName = juce::File::getSpecialLocation(juce::File::invokedExecutableFile).getParentDirectory().getFullPathName() + "\\CNCUSBController.pdf";
#endif
#if JUCE_LINUX
    fileName = juce::File::getSpecialLocation(juce::File::invokedExecutableFile).getParentDirectory().getFullPathName() + "/CNCUSBController.pdf";
#endif
    
juce::File file(fileName);
if (file.existsAsFile())
{
    juce::Process::openDocument("file:" + fileName, juce::String::empty);
}
else
{
    juce::AlertWindow::showMessageBox(juce::AlertWindow::WarningIcon, "Warning", "Help file does not exist!", juce::String::empty, nullptr);
}

#6

Ouch! Please never use raw strings to create path names!

Always use methods like File::getChildfile, which avoids this kind of messy, non-DRY and error-prone code!


#7

Thank you. This looks much better. Your help is very appreciated.

juce::File file = juce::File::getSpecialLocation(juce::File::invokedExecutableFile).getParentDirectory().getChildFile("CNCUSBController.pdf");


if (file.existsAsFile())
{
  juce::Process::openDocument("file:" + file.getFullPathName(), juce::String::empty);
}
else
{
  juce::AlertWindow::showMessageBox(juce::AlertWindow::WarningIcon, "Warning", "Help file does not exist!", juce::String::empty, nullptr);
}

#8

getSiblingFile would have been even better in this case ;)


#9

Again, thank you.

 


#10

Thanks for this thread. Most helpful :-)