Hi Christian,
You can use PHP to construct a your headers and footers into a div or other page element with an id attribute, and you can then take them out of the regular document flow and into the header and footer margin areas. Your stylesheet might look something like this:
@page {
size: A4; margin-top: 50mm; margin-bottom: 15mm;
@top { content: flow(header); vertical-align: top; }
@bottom { content: flow(footer); vertical-align: middle; }
}
#header { flow: static(header); }
#footer { flow: static(footer); }
This will move the elements with the id's of "header" and "footer" into the header and footer margin areas.
One thing you should be aware of when diverting elements from the main flow into a margin flow is that the element being diverted will loose some of it's CSS properties in the translation. So if you find your header or footer looking different than you expect, you will need to wrap it in another div and divert that div to the new flow instead, so the contents inside retain all their CSS properties.