[Tex/LaTex] Use includepdf in beamer class and keep pagestyle but counting up the pages

beamerpage-numberingpdfpages

I'm creating a beamer document in that several PDF documents get included by a python script.
To keep the style of the slides and including the PDFs I'm using the \includepdf like that:

\setbeamercolor{background canvas}{bg=}
\includepdf[pages={1-},width = 0.9\\textwidth,pagecommand={}]{*Path}

The *Path gets replaced with the PDF name by the python script.
The problem is, that the page numbers are not getting updated with the added PDFs.

On the other hand I found at: Base document page numbers with pdfpages

A way to add the page numbers with:

\includepdf[pages=-,pagecommand=\thispagestyle{plain}]{filename}

But in that case my header and footer get lose.

Does someone as an idea how to combine both?

Greetings

Stefan

EDIT

A (hopefully) MWE that shows my problem:

\documentclass{beamer}
\mode<presentation>
{
\usetheme{Warsaw}
}
\usepackage[ngerman]{babel}
\usepackage{pdfpages}

%%---------FootLine------------------------
\setbeamertemplate{footline}
{%
\centering
\begin{tabular*}{\textwidth}{l@{\extracolsep\fill}c c c c}
    \hline
     & & & \\
    & \insertshorttitle & \today &   {\insertframenumber}
\end{tabular*} 
}

\setbeamertemplate{headline}
{
  \leavevmode%
  \hbox{%
  \hspace{2em}
  \begin{beamercolorbox}[wd=\paperwidth,ht=8.25ex,dp=3.5ex]{}%
    \raggedright  
    \vbox to 7.25ex{\vfil\hbox{\sffamily\Large\color{orange}\insertsection}\vfil}\\
    \vbox to0.25ex{\vfil\hbox{\sffamily\Large\color{orange}\insertsubsection}\vfil}    
  \end{beamercolorbox}%
  }%
}

\setbeamertemplate{frametitle}
{\vskip-3pt
  \leavevmode
  \hbox{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1.6ex,dp=1ex]{black_white}%
    \raggedright
    \hspace*{2em}
    {\normalsize\insertframetitle}
  \end{beamercolorbox}
  }%
}

\begin{document}
    \section*{First Section}
    \begin{frame}
        Hello1
    \end{frame}
    \newpage
    \begin{frame}
        Hello2
    \end{frame}
    \section*{PDF Test}
    \setbeamercolor{background canvas}{bg=}
    \includepdf[pages={-},width=0.9\textwidth,pagecommand={}]{test.pdf}
\end{document}

Best Answer

I found the solution by following your loop tip. I included the forloop package, read out the maximum page number of the PDF document in python and create the for loop just when needed.

Just for your information, that is the test code of my solution:

\documentclass{beamer}
\mode<presentation>
{
\usetheme{Warsaw}
}
\usepackage[ngerman]{babel}
\usepackage{forloop}

%%---------FootLine------------------------
\setbeamertemplate{footline}
{%
\centering
\begin{tabular*}{\textwidth}{l@{\extracolsep\fill}c c c c}
    \hline
     & & & \\
    & \insertshorttitle & \today &   {\insertframenumber}
\end{tabular*} 
}

\setbeamertemplate{headline}{%
  \leavevmode%
  \hbox{%
  \hspace{2em}
  \begin{beamercolorbox}[wd=\paperwidth,ht=8.25ex,dp=3.5ex]{}%
    \raggedright  
    \vbox to 7.25ex{\vfil\hbox{\sffamily\Large\color{orange}\insertsection}\vfil}\\
    \vbox to0.25ex{\vfil\hbox{\sffamily\Large\color{orange}\insertsubsection}\vfil}    
  \end{beamercolorbox}%
  }%
}

\setbeamertemplate{frametitle}
{\vskip-3pt
  \leavevmode
  \hbox{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1.6ex,dp=1ex]{black_white}%
    \raggedright
    \hspace*{2em}
    {\normalsize\insertframetitle}
  \end{beamercolorbox}
  }%
}

\begin{document}
    \section*{First Section}
    \begin{frame}
        Hello1
    \end{frame}
    \newpage
    \begin{frame}
        Hello2
    \end{frame}
    \section*{PDF Test}
    \newcounter{ct}
    \forloop{ct}{1}{\value{ct} < 4}%
    {%
        \begin{frame}
            \includegraphics[page=\value{ct}, width=0.9\textwidth]{test.pdf}
        \end{frame}
    }
\end{document}

@JohnKormylo Thanks for your advice!

Related Question