Make interactive icons in pdf in article

cross-referencinginteraction

enter image description hereenter image description hereI really want in my book pdf file (article) on each page at the bottom to have interactive icons like in beamer. Namely: go to the next page, to the previous one, go to the next/previous section/subsection/subsubsection. Ideally, you need to move on to the next subsection if there is no nearest subsection. For example, after 4.8.1–4.8.2 and then 4.9.
Attached my terrible code and a screenshot of what I would like to get (only the panel at the bottom, not on the right as in the screenshot). I haven't been able to do anything all day:(

\usepackage[margin=1.5cm, a4paper]{geometry}
\usepackage{fontspec, titlesec}
\setmainfont{Times New Roman}
\usepackage{polyglossia, textgreek}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{hyperref, lastpage, etoolbox, refcount}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[C]{%
  \begin{tikzpicture}[overlay, remember picture]
    % rectangle 
    \fill[blue!20] ([xshift=2cm, yshift=0.5cm]current page.south west) rectangle ([xshift=-2cm, yshift=1cm]current page.south east);
    % icons
    \ifnum\value{page}>1
        \node[align=center] at ([xshift=1cm, yshift=0.75cm]current page.south) {%
        \hyperlink{page.\the\numexpr\value{page}-1\relax}{\tikz\fill[red] (0,0) circle (5pt);}};
    \fi
    
    \ifnum\value{page}>1
        \ifnum\value{page}<\getpagerefnumber{LastPage}
            \node[align=center] at ([xshift=-1cm, yshift=0.75cm]current page.south) {%
            \hyperlink{page.\the\numexpr\value{page}+1\relax}{\tikz\fill[green] (0,0) circle (5pt);}};
        \fi
    \fi
    
    \ifnum\value{page}>1
        %\ifnum\getrefnumber{section.\number\numexpr\value{section}\relax}>0
            \node[align=center] at ([xshift=-3.5cm, yshift=0.75cm]current page.south) {%
            \hyperlink{section.\number\numexpr\value{section}+1\relax}{\tikz\fill[black] (0,0) circle (5pt);}};
        %\fi
    \fi
    
    \ifnum\value{page}>1
        \node[align=center] at ([xshift=3.5cm, yshift=0.75cm]current page.south) {%
        \hyperlink{section.\number\numexpr\value{subsection}+1\relax}{\tikz\fill[white] (0,0) circle (5pt);}};
    \fi

  \end{tikzpicture}
}

% Marking sections with the section number
\preto{\section}{%
  \ifnum\value{section}>0
    \label{section.\number\value{section}}
  \fi
}

\preto{\subsection}{%
  \ifnum\value{subsection}>0
    \label{subsec:\thesection:\thesubsection}
  \fi
}

\begin{document}

\section{s1}
\subsection{ghjffgo}
\lipsum[1-40]

\section{s2}
\lipsum[11-40]

\section{s3}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\end{document}

SECOND VARIANT BUT DOSNT WORK SUBSEC

\usepackage[margin=1.5cm, a4paper]{geometry}
\usepackage{fontspec, titlesec}
\setmainfont{Times New Roman}
\usepackage{polyglossia, textgreek}
\usepackage{fancyhdr}
\usepackage{hyperref, lastpage, etoolbox, refcount}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[C]{%
  \ifnum\value{page}>1
    \raisebox{0.75cm}{%
      \hyperlink{page.\the\numexpr\value{page}-1\relax}{\fbox{\strut Previous Page}}
      \hspace{1cm}
      \hyperlink{section.\number\numexpr\value{section}+1\relax}{\fbox{\strut Next Section}}
      \hspace{1cm}
      \hyperlink{subsec:\number\value{section}:\number\numexpr\value{subsection}+1\relax}{\fbox{\strut Next Subsection}}
    }%
  \fi
}

\preto{\section}{%
  \ifnum\value{section}>0
    \label{section.\number\value{section}}
  \fi
}

\preto{\subsection}{%
  \ifnum\value{subsection}>0
    \label{subsec:\thesection:\thesubsection}
  \fi
}

\begin{document}

\section{s1}
\subsection{ghjffgo}
\lipsum[1-40]

\section{s2}
\lipsum[11-40]

\section{s3}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\end{document}

Best Answer

The links work as I think they are meant to, but I'm not sure if I think they are meant to work in the way they are meant to work. The double-arrow links always point to the next/previous division, whether that be a section or a subsection.

Note that you cannot leave the link node empty or hyperref unhelpfully 'suppresses' the 'empty' link, which is most frustrating (especially if you don't realise that's why it thinks it is empty).

On the other hand, I'm also reasonably certain this is completely wrong ....

Caveat emptor

\documentclass{article}
\usepackage[margin=1.5cm, a4paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{calc}
\usepackage{lipsum}
\usepackage{fontawesome}
\usepackage[colorlinks]{hyperref}
\newcommand\nextpage{\faAngleRight}
\newcommand\prevpage{\faAngleLeft}
\newcommand\nextdiv{\faAngleDoubleRight}
\newcommand\prevdiv{\faAngleDoubleLeft}
\makeatletter
\let\ps@plain\ps@empty
\makeatother
\pagestyle{plain}
%% hyperref doc div 15
% ateb: https://tex.stackexchange.com/a/718065/
\ExplSyntaxOn
\cs_generate_variant:Nn \property_record:nn { en }
\cs_generate_variant:Nn \property_ref:nn { en }
\hook_gput_code:nnn {shipout/lastpage} {.}
{
  \property_record:nn {mypage last page} {abspage,secnum}
}
\hook_gput_code:nnn {begindocument/end} {.}
{
  \int_gset:Nn \g_mypage_lastpage_int { \property_ref:nn { mypage last page } { abspage } }
  \int_gset:Nn \g_mypage_lastsec_int { \property_ref:nn { mypage last page } { secnum } }
}
\int_new:N \g_mypage_lastpage_int
\int_new:N \g_mypage_lastsec_int
\int_new:N \g_mypage_sec_int
\property_new:nnnn { secnum } { now } { 0 } { \int_to_arabic:n { \g_mypage_sec_int }}
\hook_gput_code:nnn {cmd/section/before} {.}
{
  \int_gincr:N \g_mypage_sec_int
  \MakeLinkTarget{secnum}
}
\hook_gput_code:nnn {cmd/subsection/before} {.}
{
  \int_gincr:N \g_mypage_sec_int
  \MakeLinkTarget{secnum}
}
\cs_new_nopar:Npn \theHsecnum { \int_to_arabic:n { \g_mypage_sec_int } }
\hook_gput_code:nnn {shipout/background} {.}
{
  \property_record:en {mypage : \int_to_arabic:n \g_shipout_readonly_int} {pagetarget}
  \put (0pt,-\paperheight) {
    \begin{tikzpicture}[]
      \path (0pt,0pt) -- ++(\paperwidth,\paperheight);
      % rectangle 
      \fill[blue!20] (2cm,5mm) rectangle ++({\paperwidth-4cm},5mm);
      % icons
      \begin{scope}[xshift=.5\paperwidth,yshift=7.5mm,node ~ distance=7.5mm,every ~ node/.append ~ style={inner ~ sep=2.5pt}]
        \node [anchor=center] (page) at (0pt,0pt) {\int_to_arabic:n {\g_shipout_readonly_int} };
        \int_compare:nNnTF { \g_shipout_readonly_int } > { 1 }
        {
          \node [left=of ~ page] (prevpage) {%
            \hyperlink{\property_ref:en { mypage:\int_to_arabic:n {\g_shipout_readonly_int-1}}{pagetarget} }{\prevpage}};
        }{
          \node  [left=of ~ page] (prevpage) {%
            \phantom{\prevpage}};
        }
        \int_compare:nNnTF { \g_shipout_readonly_int } < { \g_mypage_lastpage_int }
        {
          \node [right=of ~ page] (nextpage) {%
            \hyperlink{\property_ref:en { mypage:\int_to_arabic:n {\g_shipout_readonly_int+1}}{pagetarget} }{\nextpage}};
        }{
          \node [right=of ~ page] (nextpage)  {%
            \phantom{\nextpage}};
        }
        \int_compare:nNnTF { \g_mypage_sec_int } > { 1 }
        {
          \node [left=of ~ prevpage] (prevdiv)  {%
            \hyperlink{ secnum .  \int_to_arabic:n {\g_mypage_sec_int-1} } {\prevdiv}};
        }{
          \node  [left=of ~ prevpage] (prevdiv) {%
            \phantom{\prevdiv}};
        }
        \int_compare:nNnTF { \g_mypage_sec_int } < { \g_mypage_lastsec_int }
        {
          \node  [right=of ~ nextpage] (nextdiv) {%
            \hyperlink{ secnum .  \int_to_arabic:n {\g_mypage_sec_int+1} } {\nextdiv}};
        }{
          \node [right=of ~ nextpage] (nextdiv) {%
            \phantom{\nextdiv}};
        }
      \end{scope}
    \end{tikzpicture}%
  }%
}
\ExplSyntaxOff
\begin{document}
\section{s1}
\subsection{ghjffgo}
\lipsum[1-40]

\section{s2}
\lipsum[11-40]

\section{s3}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\end{document}

EDIT

Adding links to the first and last pages is easier because you don't need to calculate anything.

\documentclass{article}
\usepackage[margin=1.5cm, a4paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{calc}
\usepackage{lipsum}
\usepackage{fontawesome}
\usepackage[colorlinks]{hyperref}
\newcommand\nextpage{\faAngleRight}
\newcommand\prevpage{\faAngleLeft}
\newcommand\nextdiv{\faAngleDoubleRight}
\newcommand\prevdiv{\faAngleDoubleLeft}
\newcommand\firstpage{\faFastBackward}
\newcommand\finalpage{\faFastForward}
\makeatletter
\let\ps@plain\ps@empty
\makeatother
\pagestyle{plain}
%% hyperref doc div 15
% ateb: https://tex.stackexchange.com/a/718065/
\ExplSyntaxOn
\cs_generate_variant:Nn \property_record:nn { en }
\cs_generate_variant:Nn \property_ref:nn { en }
\hook_gput_code:nnn {shipout/lastpage} {.}
{
  \property_record:nn {mypage last page} {abspage,secnum}
}
\hook_gput_code:nnn {begindocument/end} {.}
{
  \int_gset:Nn \g_mypage_lastpage_int { \property_ref:nn { mypage last page } { abspage } }
  \int_gset:Nn \g_mypage_lastsec_int { \property_ref:nn { mypage last page } { secnum } }
}
\int_new:N \g_mypage_lastpage_int
\int_new:N \g_mypage_lastsec_int
\int_new:N \g_mypage_sec_int
\property_new:nnnn { secnum } { now } { 0 } { \int_to_arabic:n { \g_mypage_sec_int }}
\hook_gput_code:nnn {cmd/section/before} {.}
{
  \int_gincr:N \g_mypage_sec_int
  \MakeLinkTarget{secnum}
}
\hook_gput_code:nnn {cmd/subsection/before} {.}
{
  \int_gincr:N \g_mypage_sec_int
  \MakeLinkTarget{secnum}
}
\cs_new_nopar:Npn \theHsecnum { \int_to_arabic:n { \g_mypage_sec_int } }
\hook_gput_code:nnn {shipout/background} {.}
{
  \property_record:en {mypage : \int_to_arabic:n \g_shipout_readonly_int} {pagetarget}
  \put (0pt,-\paperheight) {
    \begin{tikzpicture}[]
      \path (0pt,0pt) -- ++(\paperwidth,\paperheight);
      % rectangle 
      \fill[blue!20] (2cm,5mm) rectangle ++({\paperwidth-4cm},5mm);
      % icons
      \begin{scope}[xshift=.5\paperwidth,yshift=7.5mm,node ~ distance=7.5mm,every ~ node/.append ~ style={inner ~ sep=2.5pt}]
        \node [anchor=center] (page) at (0pt,0pt) {\int_to_arabic:n {\g_shipout_readonly_int} };
        \int_compare:nNnTF { \g_shipout_readonly_int } > { 1 }
        {
          \node [left=of ~ page] (prevpage) {%
            \hyperlink{\property_ref:en { mypage:\int_to_arabic:n {\g_shipout_readonly_int-1}}{pagetarget} }{\prevpage}};
        }{
          \node  [left=of ~ page] (prevpage) {%
            \phantom{\prevpage}};
        }
        \int_compare:nNnTF { \g_shipout_readonly_int } < { \g_mypage_lastpage_int }
        {
          \node [right=of ~ page] (nextpage) {%
            \hyperlink{\property_ref:en { mypage:\int_to_arabic:n {\g_shipout_readonly_int+1}}{pagetarget} }{\nextpage}};
        }{
          \node [right=of ~ page] (nextpage)  {%
            \phantom{\nextpage}};
        }
        \int_compare:nNnTF { \g_mypage_sec_int } > { 1 }
        {
          \node [left=of ~ prevpage] (prevdiv)  {%
            \hyperlink{ secnum .  \int_to_arabic:n {\g_mypage_sec_int-1} } {\prevdiv}};
        }{
          \node  [left=of ~ prevpage] (prevdiv) {%
            \phantom{\prevdiv}};
        }
        \int_compare:nNnTF { \g_mypage_sec_int } < { \g_mypage_lastsec_int }
        {
          \node  [right=of ~ nextpage] (nextdiv) {%
            \hyperlink{ secnum .  \int_to_arabic:n {\g_mypage_sec_int+1} } {\nextdiv}};
        }{
          \node [right=of ~ nextpage] (nextdiv) {%
            \phantom{\nextdiv}};
        }
        \int_compare:nNnTF { \g_shipout_readonly_int } > { 1 }
        {
          \node [left=of ~ prevdiv] (firstpage) {%
            \hyperlink{\property_ref:en { mypage:1}{pagetarget} }{\firstpage}};
        }{
           \node [left=of ~ prevdiv] (firstpage) {%
             \phantom{\firstpage}};
        }
        \int_compare:nNnTF { \g_shipout_readonly_int } < { \g_mypage_lastpage_int }
        {
          \node [right=of ~ nextdiv] (finalpage) {%
            \hyperlink{\property_ref:en { mypage:\int_to_arabic:n {\g_mypage_lastpage_int}}{pagetarget} }{\finalpage}};
        }{
          \node [right=of ~ nextdiv] (finalpage)  {%
            \phantom{\finalpage}};
        }
      \end{scope}
    \end{tikzpicture}%
  }%
}
\ExplSyntaxOff
\begin{document}
\section{s1}
\subsection{ghjffgo}
\lipsum[1-40]

\section{s2}
\lipsum[11-40]

\section{s3}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\lipsum[21-40]
\subsection{ghjffgo}
\end{document}

As I mentioned in a comment, I only used fontawesome because I know it is compatible with all engines (pdfTeX, XeTeX, LuaTeX etc.) and because it provides an easy source of symbols. If you have an alternative set of symbols, just substitute them in the definitions of \prevdiv etc. It is also possible to draw something with TikZ, as you did in your question, but you shouldn't nest tikzpictures and you need some text or the hyperlink gets 'suppressed'. So then you need to mess around with \phantom again.

I also used fontawesome because your screenshot used symbols and these seemed clearer to me than differently coloured dots.

Related Question