I am trying to include a footer on each page that would link to the table of contents but this footer ("Contents") does not show up on pages where pdf is inserted. It shows up on pages with section though (where pdf is not empty). Does anyone know how to solve this?
\documentclass[a4paper]{book} %11pt b4
%\usepackage{preamble}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\usepackage{hyperref}
\fancypagestyle{mainmatter-pages}{%
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\renewcommand{\footrulewidth}{0pt}% Remove footer rule
\fancyfoot[L]{\hyperref[ToC-first-page]{Contents}}
\fancyfoot[C]{\thepage}
}
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
\cleardoublepage
\phantomsection% Place hyperlink marker
\label{ToC-first-page}% Set \label for hyperlink
\oldtableofcontents
}
\let\oldmainmatter\mainmatter
\renewcommand{\mainmatter}{%
\cleardoublepage
\oldmainmatter
\pagestyle{mainmatter-pages}%
}
\begin{document}
% contents
% CONTENTS
\newpage
\frontmatter
\pagenumbering{gobble}
\hypertarget{contents}{}
\tableofcontents
\newpage
\pagenumbering{arabic}
\setcounter{page}{1}
\mainmatter
\section{Section 1}
\includepdf[pages=-]{filename1.pdf}
\section{Section 2}
\includepdf[pages=-]{filename2.pdf}
\end{document}
This code is based on this question: Reference to the Table of Contents page (link in the bottom of the page).

\includepdf[pages=-,pagecommand={}]{filename1.pdf}– Ivan Apr 06 '21 at 20:18