2

I'm trying to customize header and footer while inserting a pdf using a hand-made command: \setlayout (3 parameters)

\includepdf[pagecommand={\setlayout{Left corner}{Center}{Right corner}}]{my file.pdf}

First I tried :

\documentclass[11pt,a4paper]{article}
\usepackage{pdfpages}

    \newcommand{\setlayout}{3}
    \thispagestyle{
    \lhead{#1}
    \chead{#2}
    \rhead{#3}
    }

\begin{document} 
\includepdf[pages=-,pagecommand={\setlayout{Left corner}{Center}{Right corner}}]{my file.pdf}
\end{document}

But, of course, it did not work.

So I would like to create a flexible (as I am going to use it several times) \setlayout command in order to customize header and footer only where the pdf is displayed

  • 2
    Welcome to TeX.SE! Please make your code snippets compilable ... – Mensch Jun 15 '17 at 19:50
2

Here is a suggestion using package fancyhdr to define an own style for pages included by \includepdf:

\documentclass[11pt,a4paper]{article}
\setlength\headheight{13.6pt}% as suggested by fancyhdr
\usepackage{mwe}% only for dummy text and example pdf page
\usepackage{pdfpages}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[C]{normal pages}

\fancypagestyle{pdfpages}{
  \fancyhf{}
  \fancyhead[L]{\pdfpagesheaderleft}
  \fancyhead[C]{\pdfpagesheadercenter}
  \fancyhead[R]{\pdfpagesheaderright}
}
\newcommand*\pdfpagesheaderleft{}
\newcommand*\pdfpagesheadercenter{}
\newcommand*\pdfpagesheaderright{}

\newcommand{\setlayout}[3]{\thispagestyle{pdfpages}%
  \gdef\pdfpagesheaderleft{#1}%
  \gdef\pdfpagesheadercenter{#2}%
  \gdef\pdfpagesheaderright{#3}%
}

\begin{document}
\Blindtext
\includepdf[pages=-,
  pagecommand=\setlayout{Left corner}{Center}{Right corner},
  width=\textwidth,height=\textheight,keepaspectratio
]{example-image-a4.pdf}
\Blindtext
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.