Forum How do I...?

How to....use dynamic header and footer

Christian
Hi! Is it possibible use dynamic content to put in the header and the footer take from a database?...for example we use a table, in this table there are 3 fields, header, body, footer. Now I go to edit a text (the body). Then when I go to print my document I wanna use also the header and footer and also I wanna header and footer present in every page print of the document. In particular we use PHP on MySQL db.

Any idea?

Thanks to all!!!

Christian
whittaker007
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.
Christian
Hi!!

Really thanks for the information, I have tried your same solution with static text. A question. Can I pass only a html extension file into prince? Now,or better tomorrow, I'll try to pass an php file....I hope it work...

Thanks,
Christian
whittaker007
Anything that produces output in HTML or XML should work fine.
Christian
Hi!!!...I solve the trouble of dynamic header and footer. But I try different modes to manage many printing page. I find my header in every sheet but the footer only in the last one. Any ideas?

thanks to all

Christian
mikeday
The footer element may need to be moved to the top of the document, with the header element, in order to appear on every page.
whittaker007
That's strange, I have my footer markup at the bottom of a long document which is diverted into the footer margin flow using the CSS above. It prints the footer at the bottom of every page in the PDF output.

However if I combine multiple documents on the Prince command line to produce a single PDF output, I get the footer only on the first page - not the last.
Christian
Hi!!! Thank Mike for the answer, now I'm trying your solution. Another question. Do you use some CSS tag for the break page?

Thanks
Christian
mikeday
Use the page-break-before and page-break-after properties.