Add colour shape to header on external pdf file with Latex

header-footerpdfpagesshapestikz-pgf

I am working on a scanned PDF document to add a rectangular shape on the header to hide header text on all pages of the entire document. To incorporate the external PDF's I use the pdfpages package. Does anyone here know if, and if yes, how it can be done?

I'm stumped, any help will be appreciated.

Here is the code :

\documentclass[12pt]{article}

\usepackage{pdfpages}
\usepackage{tikz}

\newcommand{\mycbox}[1]{\tikz{\path[draw=#1,fill=#1] (0,0) rectangle (15cm,1cm);}}

\begin{document}
 \mycbox{red}

\includepdf[pages=-,picturecommand*={\put(400,680){\Huge Some text}}]{original.pdf}
\end{document}

The screenshot of the original pdf is :

enter image description here

And the required output should be:
enter image description here

The source pdf is here.

Best Answer

You can use the current page Tikz node's anchors and overlay the page with a Tikz picture. I used two rectangles, red and white, like in the desired output.

Adjust the yshift= parameter as desired.

header hidden

MWE

\documentclass[12pt]{article}

\usepackage{pdfpages}
\usepackage{tikz}

\newcommand{\mycbox}[2]{
\begin{tikzpicture}[remember picture,overlay]
 \draw[#1,fill=#1] (current page.north west) rectangle ([yshift=-1.5cm]current page.north east);
 \draw[#2,fill=#2] ([yshift=-1.5cm]current page.north west) rectangle ([yshift=-3cm]current page.north east);
\end{tikzpicture}
}

\begin{document}

\includepdf[pages=-,picturecommand*={ \mycbox{red}{white}}]{original.pdf}
\end{document}

Edited to add:

To keep the original border frame visible, you can shrink the overlaid rectangles slightly:

header

with

 \draw[#1,fill=#1] ([xshift=1.5cm,yshift=-0.5cm]current page.north west) rectangle ([xshift=-1.45cm,yshift=-1.5cm]current page.north east);
 \draw[#2,fill=#2] ([xshift=1.5cm,yshift=-1.5cm]current page.north west) rectangle ([xshift=-1.45cm,yshift=-3cm]current page.north east);
Related Question