# Header and Footer in handout using pgfpages

I am trying to print out page number/total number of pages in the handout that I get from this code: This is my MWE:

\documentclass[11 pt, handout,xcolor=pdftex,x11names,table]{beamer}
\mode<beamer>{\usetheme{CambridgeUS}}
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[letterpaper,border shrink=10mm]
\pgfpageslogicalpageoptions{1}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{2}{border code=\pgfusepath{stroke}}

\begin{document}

\begin{frame}
\frametitle{First}
\begin{itemize}
\item check1
\item check 2
\end{itemize}
\end{frame}

\begin{frame}
Text 1
\end{frame}

\end{document}


I am well aware that I can do it using pDfpages as pointed out in Actual page number (and total number of pages) in the handout . However, the problem with using pDfpages is that it does not preserve the original document's bookmarks. I was wondering if this is possible to do using pGfpages or any other package?

-
I had to read this a few times to notice the difference between pdfpages and pgfpages (pGf vs pDf)! This comment may help someone else too... –  cyberSingularity Nov 19 '12 at 1:12
Thank you! I also edited the question make it very clear –  N Nik Nov 19 '12 at 1:23
My only idea so far would be to use the textpos package and add some textblock* environments as part of the border code for the first logical page, and put the header/footer in those, but it would need a fair amount of work which I'm afraid I'm not able to do right now, but maybe this will be a starting point for someone to find a solution... –  cyberSingularity Nov 19 '12 at 1:34

Here's a possible solution using the lastpage package to get the total number of pages and the background package to place the text <current page> of <total pages>; I counted only physical (not logical) pages of the handout, but this can be easily changed if desired. I chose to place the text centered at the top, but this can also be easily changed:

\documentclass[11 pt, handout,xcolor=pdftex,x11names,table]{beamer}
\mode<beamer>{\usetheme{CambridgeUS}}
\usepackage{pgfpages}
\usepackage{lastpage}
\usepackage{refcount}
\usepackage{ifthen}
\pgfpagesuselayout{2 on 1}[letterpaper,border shrink=10mm]
\pgfpageslogicalpageoptions{1}{border code=\pgfusepath{stroke}}
\pgfpageslogicalpageoptions{2}{border code=\pgfusepath{stroke}}

\usepackage{background}
\SetBgAngle{0}
\SetBgScale{1}
\SetBgOpacity{1}
\SetBgColor{black}
\SetBgPosition{current page.north}
\SetBgVshift{10pt}
\SetBgContents{}
\makeatletter
\ifthenelse{\isodd{\thepage}}%
{\SetBgContents{\the\numexpr\thepage/2\relax\ of \the\numexpr\getpagerefnumber{LastPage}/2\relax}}%
{\SetBgContents{}}%
\bg@material}
\makeatother

\begin{document}

\begin{frame}
\frametitle{First}
\begin{itemize}
\item check1
\item check 2
\end{itemize}
\end{frame}

\begin{frame}
Text 1
\end{frame}

\begin{frame}
Text 2
\end{frame}

\begin{frame}
Text 3
\end{frame}

\begin{frame}
Text 4
\end{frame}

\end{document}


-
Thank you so much; this works like a charm! –  N Nik Nov 19 '12 at 2:06
Interested reader may also look at this post as well: tex.stackexchange.com/questions/82920/… –  N Nik Nov 19 '12 at 2:09