Open a pdf file in Ubuntu 12.04

Question:
Is there some special code or setting that is required to open an existing .pdf file in Ubuntu 12.04?
I hate to bother folks but this is such a simple chore in every other tool and environment that I’ve worked in that the fact that I can’t get this working in Linux is really frustrating.

Background:
I am not experienced enough with Linux to even be called a beginner. I’m just groping in the dark!
I have built a desktop application that runs nicely on Windows and Mac.
On the Linux platform I’ve run into two problems (everything else seems to work fine) that I have not as yet been able to resolve.

  1. I can’t find a way to open a .pdf file (double click works and I even installed Adobe for Linux but no joy)
  2. I can’t get the WebViewer to function in Linux (HTMLViewer requires libwebkit/libwebkitgtk or libgtkhtml error)

Behavior on Linux (problem 1) is to run up to the Launch method and then nothing happens.
Behavior on Linux (problem 2) is to throw an error

Research:
The XoJo Blog and documentation
Google

Configuration:
iMac running Parallels and Ubuntu 12.04
XoJo 2013 Release R4.1
sudo apt-get install ia32-libs was run
sudo apt-get install libwebkitgtk-1.0.0 was run as well
Parallels was shut down and restarted

Code:
Problem 1
Dim f As FolderItem
f = GetFolderItem(UsePath) where UsePath is an existing .pdf document within the OS file system
f.Launch()

Problem 2
WebViewer.LoadURL(address)

Thanks for any help you can offer.

Regards,

Mark Donges
419Systems.com

Try something like

Dim f As FolderItem
f = GetOpenFolderItem("") // this should give you dialog to select a file so select the PDF
if f <> nil then f.Launch() // if you cancel the open file dialog then f can be nil

This should launch the default application on Ubuntu set to open PDF files
I’ll confess I’m not a Linux expert so I’m not sure how Ubuntu tracks what apps are defaults
But it’s not supposed to be any more than this

For the web viewer what address did you use (you should be able to use a file:// URI)

Ah figures
There IS a bug reported on Linux that may affect your results :frowning:
Basically if the path to the PDF has spaces in it then it fails (which is exactly what I was seeing initially)

I did have a pace in the path, which I removed.
The executable (desktop application) has a folder at the same location which contains a series of .pdf files. The logic I’m using to discover the path to the folder so I can open the selected pdf file is:

Dim f As FolderItem
Dim g As FolderItem
Dim UsePath As String

If Debugging Then
f = GetFolderItem("").parent
Else
f = GetFolderItem("")
End If

UsePath = f.NativePath + “PDF” + OS_Separator + Selected_PDF_File_Name
g = GetFolderItem(UsePath, FolderItem.PathTypeNative)

In every instance the folderitem g is instantiated and in every instance the “Exists” property is False and the document is not opened.

In trying the GetOpenFolderItem("") I wind up in the Recently Used area of the file system. Once I navigate to the correct location (I can set he default folder to open) and double click on the desired .pdf file then the document is opened as you would expect it to be.

My objective is to avoid the additional steps for the customer. They’ve already selected the topic from a searchable process that “knows” about the file names.

Thanks,

Mark

“Pace” should have been “Space”

Regarding the Web Viewer, I am setting the WebHTMLViewer.URL to “http://419Systems.com
This works for Windows and Mac…

[quote=55380:@Mark Donges]If Debugging Then
f = GetFolderItem("").parent
Else
f = GetFolderItem("")
End If

UsePath = f.NativePath + “PDF” + OS_Separator + Selected_PDF_File_Name
g = GetFolderItem(UsePath, FolderItem.PathTypeNative)

[/quote]
If F is already in the right parent folder then do

     g = f.CHild("PDF").Child(Selected_PDF_Fle_Name)

should be correct
But definitely check g in the debugger to see if it actually has the location you expect for the path

The web viewer, once you have the correct libraries installed, should just work.
I’m using a 32 bit distro but didn’t have to install anything extra
I prefer webkit & so I set the browser type to WebKit (the very last property) and away it went to the URL I told it to load (http://www.google.com)

You should avoid this kind of path construction at all costs. Use f.Child, as Norman suggests.

If Exists is false, then your path was bad and you didn’t actually get the file. See above.

Nice

Thanks for the suggestion on how to properly address the desired file.
Works like a champ on a Windows machine and I have no doubt that the Mac OS will make nice too.

However, I’ve implemented that code in Linux but with no luck. I can successfully address any folders I want to but individual files are another matter.
Is this some special Linux thing?
I’ve tried to hard code the file name (copied directly from the Properties form) and it still can’t resolve the problem.
If I use a GetOpenFolderItem it will open the selected file properly.

Use GetOpenFolderItem and pull the path out of the file it returns. Then compare that to the path you get when you access the file in code.

I’ve actually done that. Copied and pasted both into a text editor to evaluate as much as possible. They were identical.
I just wonder if there is some issue with Linux. I’m totally a novice using Linux so who knows what I may have missed. I just accepted the settings and applied the only recommended changes to make the 64 bit version run Xojo.
Another interesting behavior is that there is no place on the dialog to display the suggested file name. Way different from Windows…
Linux is rapidly becoming more trouble than it is worth…

Here’s the ironic part, my app actually runs great with the exception of the two problems outlined above. Very confusing.
Oh, and I tried to set the initial directory but it won’t recognize the path. It’s like it ignores the .Child method.

Thanks very much

Did you look at the hex values? I have seen plenty of cases where a file/folder name in linux contained an unprintable character.

No, didn’t go to that level but I can.

You might want to try using the xojo shell class and then run the command…

Xdg -open /path/to/pdf

You can then just run the shell execute on the command.
Xdg automatically opens the file with associated application.

Oh and linux is probably set up as case sensitive too
So make sure the names matches EXACTLY in case as well

xdg is all lowercase. If command is missing try installing with

sudo apt-get install xdg-utils

Dim s As Shell
s = New Shell
s.Execute(xdg -open /home/parallels/Documents/RealBasicXojoSource/RealSoftProjects/ss/PDF/VitalRecords.pdf)

Look about right?

Nope
Need quotes around the command itself

s.Execute("xdg -open /home/parallels/Documents/RealBasicXojoSource/RealSoftProjects/ss/PDF/VitalRecords.pdf")

Same results, no error but also the file is not opened.

I’ve had to build the path by hand because the recommended method doesn’t work in Linux.

Dim f As FolderItem
Dim g As FolderItem
f = GetFolderItem("").Parent
g = f.Child(“PDF”).Child(filenamevariable)

I can actually go as far as g = f.Child(“PDF”) and have that work, but the minute I add a file name and not a folder to the mix it fails to create the folder item.