HTML to PDF converter for Java and .NET

HOME   FEATURES   PRODUCTS   DOWNLOADS   BUY NOW!   SUPPORT
<< back

PD4ML: PDF Header/Footer Generation

 

PD4ML provides 3 types of headers/footers.

  1. text-only
  2. html (PD4ML Pro)
  3. inline (PD4ML Pro)

The first 2 options are available by PD4ML Java API calls (or as JSP custom tags mapped to PD4ML API): i.e.
<pd4ml:footer> -> pd4ml.setPageFooter();

1. Text only (in such form can be used only in JSP):
<pd4ml:footer
    pageNumberTemplate="page $[page] of $[total]"
    titleAlignment="left"
    pageNumberAlignment="right"
    color="#008000"
    initialPageNumber="1"
    pagesToSkip="1"
    fontSize="14"
    areaHeight="18"/>

Java version:
PD4PageMark footer = new PD4PageMark();
footer.setPageNumberTemplate("page $[page] of $[total]");
footer.setTitleAlignment(PD4PageMark.LEFT_ALIGN);
footer.setPageNumberAlignment(PD4PageMark.RIGHT_ALIGN);
footer.setColor(new Color(0x008000));
footer.setInitialPageNumber(1);
footer.setPagesToSkip(1);
footer.setFontSize(14);
footer.setAreaHeight(18);	
pd4ml.setPageFooter(footer);



2. HTML formatted footer (in such form can be used only in JSP)

<pd4ml:footer areaHeight="-1">
<font color="red"><i>page $[page] of $[total]</i></font>
</pd4ml:footer>

Java version:
PD4PageMark footer = new PD4PageMark();
footer.setHtmlTemplate("<font color=\"red\"><i>page $[page] of $[total]</i></font>");
footer.setAreaHeight(-1);	
pd4ml.setPageFooter(footer);


areaHeight="-1" means "autocompute" there



3. The third option, inline footer, allows to define footer body in HTML/PHP document:

<pd4ml:page.footer>
footer: $[page] of $[total]
</pd4ml:page.footer>


The definition impacts all subsequent pages after the page, where the footer defined. A new appearance of the footer overrides previously defined one.
In order to define the footer for the first page, you need to place the definition immediately after <body> tag or before <html>.

Also you may explicitly define pages, where the footer needs to be applied:

<pd4ml:page.footer scope="1">
first page footer: $[page] of $[total]<br> <img src="img1.gif">
</pd4ml:page.footer>
<pd4ml:page.footer scope="2+">
footer: $[page] of $[total]<br>
<img src="img2.gif">
</pd4ml:page.footer>
<html>
<head>
...

The above defines different footers for the first page and for the rest of the pages (the second and others). Also "scope" understands "even", "odd" and "skiplast" modifiers. Example:

scope="2,5-10,even,skiplast"

 

You may control header/footer appearance scope also if header/footer defined via API (the first two header/footer types). It can be achieved by an overriding relevant methods:

PD4PageMark footer = new PD4PageMark() {
	public String getHtmlTemplate(int pageNumber) {
		if ( pageNumber % 2 == 0 ) {
			return "<html><body>some left aligned stuff...";
		} else {
			return "<html><body>some right aligned stuff...";
		}
	}
};
pd4ml.setPageFooter(footer);


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);

etc

Note: by the approach it will allocate header or footer space even if for particular pages the overridden methods return no header/footer data.

 

PDF header/footer discussion is here

Copyright ©2004-24 zefer|org. All rights reserved. Bookmark and Share