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.
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.
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.