[903] | 1 | <HTML>
|
---|
| 2 | <HEAD>
|
---|
| 3 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
|
---|
| 4 | <TITLE>Header, footer, page break and image</TITLE>
|
---|
| 5 | <LINK TYPE="text/css" REL="stylesheet" HREF="../fpdf.css">
|
---|
| 6 | </HEAD>
|
---|
| 7 | <BODY>
|
---|
| 8 | <H2>Header, footer, page break and image</H2>
|
---|
| 9 | Here is a two page example with header, footer and logo:
|
---|
| 10 | <BR>
|
---|
| 11 | <BR>
|
---|
| 12 | <TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
|
---|
| 13 | <NOBR><code><font color="#000000">
|
---|
| 14 | <?php<br>define<font class="kw">(</font><font class="str">'FPDF_FONTPATH'</font><font class="kw">,</font><font class="str">'font/'</font><font class="kw">);<br>require(</font><font class="str">'fpdf.php'</font><font class="kw">);<br><br>class </font>PDF <font class="kw">extends </font>FPDF<br><font class="kw">{<br></font><font class="cmt">//Page header<br></font><font class="kw">function </font>Header<font class="kw">()<br>{<br> </font><font class="cmt">//Logo<br> </font>$<font class="kw">this-></font>Image<font class="kw">(</font><font class="str">'logo_pb.png'</font><font class="kw">,</font>10<font class="kw">,</font>8<font class="kw">,</font>33<font class="kw">);<br> </font><font class="cmt">//Arial bold 15<br> </font>$<font class="kw">this-></font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font>15<font class="kw">);<br> </font><font class="cmt">//Move to the right<br> </font>$<font class="kw">this-></font>Cell<font class="kw">(</font>80<font class="kw">);<br> </font><font class="cmt">//Title<br> </font>$<font class="kw">this-></font>Cell<font class="kw">(</font>30<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Title'</font><font class="kw">,</font>1<font class="kw">,</font>0<font class="kw">,</font><font class="str">'C'</font><font class="kw">);<br> </font><font class="cmt">//Line break<br> </font>$<font class="kw">this-></font>Ln<font class="kw">(</font>20<font class="kw">);<br>}<br><br></font><font class="cmt">//Page footer<br></font><font class="kw">function </font>Footer<font class="kw">()<br>{<br> </font><font class="cmt">//Position at 1.5 cm from bottom<br> </font>$<font class="kw">this-></font>SetY<font class="kw">(-</font>15<font class="kw">);<br> </font><font class="cmt">//Arial italic 8<br> </font>$<font class="kw">this-></font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'I'</font><font class="kw">,</font>8<font class="kw">);<br> </font><font class="cmt">//Page number<br> </font>$<font class="kw">this-></font>Cell<font class="kw">(</font>0<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Page '</font><font class="kw">.</font>$<font class="kw">this-></font>PageNo<font class="kw">().</font><font class="str">'/{nb}'</font><font class="kw">,</font>0<font class="kw">,</font>0<font class="kw">,</font><font class="str">'C'</font><font class="kw">);<br>}<br>}<br><br></font><font class="cmt">//Instanciation of inherited class<br></font>$pdf<font class="kw">=new </font>PDF<font class="kw">();<br></font>$pdf<font class="kw">-></font>AliasNbPages<font class="kw">();<br></font>$pdf<font class="kw">-></font>AddPage<font class="kw">();<br></font>$pdf<font class="kw">-></font>SetFont<font class="kw">(</font><font class="str">'Times'</font><font class="kw">,</font><font class="str">''</font><font class="kw">,</font>12<font class="kw">);<br>for(</font>$i<font class="kw">=</font>1<font class="kw">;</font>$i<font class="kw"><=</font>40<font class="kw">;</font>$i<font class="kw">++)<br> </font>$pdf<font class="kw">-></font>Cell<font class="kw">(</font>0<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Printing line number '</font><font class="kw">.</font>$i<font class="kw">,</font>0<font class="kw">,</font>1<font class="kw">);<br></font>$pdf<font class="kw">-></font>Output<font class="kw">();<br></font>?>
|
---|
| 15 | </font>
|
---|
| 16 | </code></NOBR></TD></TR></TABLE><P></P>
|
---|
| 17 | <SCRIPT>
|
---|
| 18 | <!--
|
---|
| 19 | if(document.location.href.indexOf('http:')==0)
|
---|
| 20 | {
|
---|
| 21 | document.write("<P CLASS='demo'><A HREF='tuto2.php' TARGET='_blank' CLASS='demo'>[Demo]</A></P>");
|
---|
| 22 | }
|
---|
| 23 | //-->
|
---|
| 24 | </SCRIPT>
|
---|
| 25 | This example makes use of the <A HREF='../doc/header.htm'>Header()</A> and <A HREF='../doc/footer.htm'>Footer()</A> methods to process page headers and
|
---|
| 26 | footers. They are called automatically. They already exist in the FPDF class but do nothing,
|
---|
| 27 | therefore we have to extend the class and override them.
|
---|
| 28 | <BR>
|
---|
| 29 | <BR>
|
---|
| 30 | The logo is printed with the <A HREF='../doc/image.htm'>Image()</A> method by specifying its upper-left corner and
|
---|
| 31 | its width. The height is calculated automatically to respect the image proportions.
|
---|
| 32 | <BR>
|
---|
| 33 | <BR>
|
---|
| 34 | To print the page number, a null value is passed as the cell width. It means that the cell
|
---|
| 35 | should extend up to the right margin of the page; it is handy to center text. The current page
|
---|
| 36 | number is returned by the <A HREF='../doc/pageno.htm'>PageNo()</A> method; as for the total number of pages, it is obtained
|
---|
| 37 | by means of the special value <TT>{nb}</TT> which will be substituted on document closure
|
---|
| 38 | (provided you first called <A HREF='../doc/aliasnbpages.htm'>AliasNbPages()</A>).
|
---|
| 39 | <BR>
|
---|
| 40 | Note the use of the <A HREF='../doc/sety.htm'>SetY()</A> method which allows to set position at an absolute location in
|
---|
| 41 | the page, starting from the top or the bottom.
|
---|
| 42 | <BR>
|
---|
| 43 | <BR>
|
---|
| 44 | Another interesting feature is used here: the automatic page breaking. As soon as a cell would
|
---|
| 45 | cross a limit in the page (at 2 centimeters from the bottom by default), a break is performed
|
---|
| 46 | and the font restored. Although the header and footer select their own font (Arial), the body
|
---|
| 47 | continues with Times. This mechanism of automatic restoration also applies to colors and line
|
---|
| 48 | width. The limit which triggers page breaks can be set with <A HREF='../doc/setautopagebreak.htm'>SetAutoPageBreak()</A>.
|
---|
| 49 | </BODY>
|
---|
| 50 | </HTML>
|
---|