# Header including description and page counter of included PDF

### The problem

A portfolio I'm creating contains a 'supporting materials' section, in which I include many several-page-long documents using the pdfpages package. Each document is in its own PDF file, and each document is formatted very differently—most are scanned documents of various sorts.

As such, navigating this supporting materials section is currently a nightmare, made only slightly easier by including page numbers of the base document (cf. this answer). If a reader flicks to a random page, especially if printed, they won't know which document they're looking at or how far through the document they are; all they'll know is the current page number within the whole portfolio.

### The dream

I would like the pages containing the included PDF documents to contain headers with specified descriptions together with a page counter. For example, suppose I include document-xyz.pdf, which contains 14 pages. On the fifth page of document-xyz.pdf, the header would say something like "Document XYZ — page 5 of 14".

### The code

My file looks a little bit like this:

\documentclass{report}

\usepackage{lipsum}
\usepackage{pdfpages}

\begin{document}

\chapter{Supporting materials}

\lipsum{1-3}

% Document 1
\includepdf[pages=-, pagecommand={}]{document1.pdf}

% Document 2
\includepdf[pages=-, pagecommand={}]{document2.pdf}

%%% ...and so on, until...

% Document N
\includepdf[pages=-, pagecommand={}]{documentN.pdf}

\end{document}


Any advice leading to progress towards achieving 'the dream' would be much appreciated.

That's not difficult:

\documentclass{report}

\usepackage{lipsum}
\usepackage{pdfpages}
\newcounter{includepdfcnt}
\newcommand\tmppagenumbers{}
\newcommand\tmpdocname{}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancypagestyle{includepdf}{%
\fancyhf{}
\chead{Document \tmpdocname{} -- page \theincludepdfcnt\ of \tmppagenumbers}}
\begin{document}

\chapter{Supporting materials}

\lipsum{1-3}

% Document 1
\setcounter{includepdfcnt}{0}
\def\tmpdocname{manypages}
\pdfximage{\tmpdocname.pdf}
\def\tmppagenumbers{\the\pdflastximagepages}

\includepdf[pages=-, pagecommand={\stepcounter{includepdfcnt}\thispagestyle{includepdf}}]{\tmpdocname}

\end{document}