You can find general info regarding PD4ML headers/footers by the link:

The third option allows you to define with scope attribute where a particular header/footer should appear. You may define multiple tags with different scopes.

If you prefer to define headers/footers via API, you need to override corresponding methods of PD4PageMark. For example:
[language=java:2gds8h30]PD4PageMark footer = new PD4PageMark() {
public String getHtmlTemplate(int pageNumber) {
if ( pageNumber % 2 == 0 ) {
return “some left aligned stuff…”;
} else {
return “some right aligned stuff…”;

The above example defines page-specific HTML footer. Such type of footers is not supported by PD4ML Std. For the Std verison you may override:

PD4PageMark.getPageNumberTemplate(int pageNr);
PD4PageMark.getPageNumberAlignment(int pageNr);
PD4PageMark.getTitleTemplate(int pageNr);