Tikz rectangle hiding text!

Using this code to achieve an effect as in the question Page border coloured.

\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\pageframe}{%
\begin{tikzpicture}[remember picture,overlay]
\fill[blue!25!] (current page.north east) rectangle (current page.south west);
\fill[white, rounded corners] ([xshift=-10mm,yshift=-17mm]current page.north east) rectangle ([xshift=10mm,yshift=17mm]current page.south west);
\end{tikzpicture}%
}


The code draws a whole-page coloured rectangle and a rounded white rectangle in between the page to create a white area for text.

But any text is not showing through (though it is selectable in PDF reader and appears as white text against white background rectangle)!

-
Where is the text? Your example is too minimal. –  Matthew Leingang May 15 '11 at 11:22
text is in \begin{document} (parts, chapters, sections...) –  yolo May 15 '11 at 11:33
We need a full example. Most likely you draw the graphic after the text. Move the code from the footer to the header and see if this helps. –  Martin Scharrer May 15 '11 at 11:34
graphic is in preamble - EDIT: in header it works! post this as an answer... –  yolo May 15 '11 at 11:37
You should add the name of the user after an @ into the comment to notify him/her. This is not required if the user is the author of the question or answer the comment is for. That's the reason Matthew and I didn't added @umar in every comment. –  Martin Scharrer May 15 '11 at 12:00

In the linked question the page frame is drawn in the footer. Moving the page frame into the header instead will change the order and should display the frame before, i.e. below, the text.

To give an explanation: As far I know the page is processed the following way: The main text is typeset and TeX collects a page worth of text. It then places the header on the page, followed by the already processed text and finally adds the footer. So material in the footer is placed above the text while material in the header is placed below it. It surprises me that the code in the linked question works as it is.

-
Thanks @Martin for this advice. I changed the example in the linked question. It now uses the header do draw the border. –  Tobi May 16 '11 at 9:09

Two solutions:

1. Draw the picture before the main text. You can use eso-pic package to do this, or put it in the header using fancyhdr.

2. Use clip instead of white filled rectangle.

-

Here is a solution that draws the region inside two rectangles using the even odd rule. It does not draw anything in the part that is inside both rectangles. With the approach given here, you get the same result using head or foot, because only the frame is drawn, not the inside. The code is

\documentclass[twoside=semi,BCOR=0cm,letterpaper]{scrbook}

\usepackage{scrpage2}

\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\pageframe}{%
\begin{tikzpicture}[remember picture,overlay]
\fill[blue!25,even odd rule]
(current page.north east) rectangle  (current page.south west)
[rounded corners] ($(current page.north east)+(-1,-1)$) rectangle ($(current page.south west)+(1,1)$);
\end{tikzpicture}%
}

% set page style
\cefoot[\pageframe]{\pageframe}
\cofoot[\pageframe]{\pageframe}