Flatpak okular problem

I am used to open pdfs from the command line. Now, using flatpak I do (via alias)

flatpak run org.kde.okular somefile.pdf

This works fine if somefile.pdf is somewhere below /var/home/manfred

I also have /var/data/ If I am within /var/data and try to open, say /var/data/somefile.pdf I get an error that the pdf cannot be found.

Opening via Dolphing works and I see something like

/app/bin/okular-bin file:///run/user/1000/doc/a551f7a1/somefile.pdf

This is really bad.

Does anybody know how I could find a way to come from /var/data/ to `a551f7a1`?

This has to do with Flatpak’s permission model. Well-packaged flatpaks (like Okular) won’t have direct access to the entire filesystem by default - they might have access to your home directory, sometimes not even that. This is usually worked around using the XDG document portal, a desktop service that dynamically makes individual files available inside the flatpak sandbox after the user selects them in a file dialog.

Obviously, this approach doesn’t work on the command line. The easiest way to work around this is to use xdg-open to open PDF files instead of calling Okular directly – xdg-open somefile.pdf will do the heavy lifting of making the PDF file open in your default PDF viewer, even if the PDF viewer’s Flatpak doesn’t otherwise have access to that directory. (xdg-open, in general, will open whatever file/URI you give it using the default GUI application for that file type or protocol. Pretty handy tool regardless.)

Alternatively, if you want to call Okular directly, you have a couple options:

  • Grant Okular permissions to read the current working directory temporarily for the one call: flatpak run --filesystem=$PWD org.kde.okular somefile.pdf
  • Grant Okular persistent permissions on a specific directory. It seems you’re on KDE; you can do this through KDE System Settings under Security & Privacy > Application Permissions > Flatpak Permissions > Okular and adding a new entry under “Filesystem Permissions” (just give the path you want to grant access to and select the appropriate access mode).
    • Most ublue desktop images also come with Flatseal, which can manage this as well. I use KDE as well and usually go through the KCM to manage permissions so I’m not as familiar with Flatseal, but the general idea should be pretty similar.
3 Likes

Thanks a lot @hal7df

For the time being I had installed okular as an rpm package and such circumvented any problems. But your background information and suggestions are very interesting.

I will go back to flatpak okular and try out things. Also xdg-open sounds very interesting.

Thanks again.

Just tested on a second system with a flatpak okular. xdg-open is a perfect solution!

1 Like

One addition.

If shell completion is important then another solution could be better.

I use fish shell and if one wants to have shell completion one should define

alias okular=‘flatpak run org.kde.okular’

Now okular shell completion is available.

However, in this case one must add the paths required for read access in KDE System Settings in Security & Privacy → Flatpak Permissions → Okular → Filesystem Access as @hal7df kindly explained above.

xdg-open is aliased to open: open blah.pdf is how I do it.

2 Likes

Interesting. This alias does exist in bash, zsh and fish.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.