I'm not sure how elegant is the method below. But it works normally for me.
I'm using ReText as Markdown editor and plan to use
[link-to-pdf](pdf-filename.pdf#page=2)
syntax for PDF with page number.
So I have defined my local xdg-open
wrapper script:
mkdir /home/$USER/bin
echo "export PATH=/home/$USER/bin:$PATH" >> .bashrc
and placed the following code to /home/$USER/bin/xdg-open
:
#!/bin/sh
pdfviewer=atril
filename="$1";
case $filename in
*.pdf#page=*)
file=$(echo "$filename" | cut -d "#" -f 1);
page=$(echo "$filename" | cut -d "#" -f 2 | sed "s/page=/-p /");
$pdfviewer "$file" $page ;;
*) /usr/bin/xdg-open "$@" ;;
esac
This script should be executable (set with chmod +x /home/$USER/bin/xdg-open
), and it will be used only if .pdf#page=
will be found, otherwise it will use system-wide /usb/bin/xdg-open
.
I have tested this method with Atril PDF viewer on my Ubuntu 16.04 LTS MATE.
You can change pdfviewer
variable to evince
if you want.
As free bonus we can use the .pdf#page=
syntax in the terminal:
xdg-open /usr/share/doc/qpdf/qpdf-manual.pdf#page=12
Note: after such manipulations we have two xdg-open
executables - the output of whereis xdg-open
should become xdg-open: /usr/bin/xdg-open /home/user/bin/xdg-open /usr/share/man/man1/xdg-open.1.gz
.