je l'utilise pour exporter des documents générés par mon site vers du pdf, et ça marche très bien. Cependant j'ai un contenu d'une longueur indéterminée (qui peut prendre 1, 2, 3 ou plus de pages) et j'ai besoin d'avoir un footer sur toutes les pages, mais il doit être différent sur la première page... J'ai donc cherché un peu partout et j'ai constaté que je ne suis pas le seul a avoir ce soucis, mais je n'ai pas trouvé de réponse satisfaisante. Je vous fait part du code que j'ai bidouillé pour arriver a mes fins:
dans html2pdf.class.pdf, a la ligne 71 on ajoute
var $subFOOTER1 = array(); // tableau des sous commandes pour faire le FOOTER de la première page
ensuite on remplace la ligne 502 par:
if($this->pdf->PageNo()==1) $this->parsing->code = $this->subFOOTER1; else $this->parsing->code = $this->subFOOTER;
a la ligne 1312 (après la fonction o_PAGE_FOOTER($param) )
function o_PAGE_FOOTER1($param) { if ($this->forOneLine) return false; $this->subFOOTER1 = array(); for($this->parse_pos; $this->parse_pos<count($this->parsing->code); $this->parse_pos++) { $todo = $this->parsing->code[$this->parse_pos]; if ($todo['name']=='page_footer1') $todo['name']='page_footer_sub1'; $this->subFOOTER1[] = $todo; if (strtolower($todo['name'])=='page_footer_sub1' && $todo['close']) break; } $this->setPageFooter(); return true; }
puis a la ligne 1468 (normalement après la fin de la fonction o_PAGE_FOOTER_SUB($param))
function o_PAGE_FOOTER_SUB1($param) { if ($this->forOneLine) return false; $this->subSTATES = array(); $this->subSTATES['x'] = $this->pdf->getX(); $this->subSTATES['y'] = $this->pdf->getY(); $this->subSTATES['s'] = $this->style->value; $this->subSTATES['t'] = $this->style->table; $this->subSTATES['ml'] = $this->margeLeft; $this->subSTATES['mr'] = $this->margeRight; $this->subSTATES['mt'] = $this->margeTop; $this->subSTATES['mb'] = $this->margeBottom; $this->subSTATES['mp'] = $this->pageMarges; // nouvel etat pour le footer $this->pageMarges = array(); $this->margeLeft = $this->defaultLeft; $this->margeRight = $this->defaultRight; $this->margeTop = $this->defaultTop; $this->margeBottom = $this->defaultBottom; $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight); $this->pdf->SetAutoPageBreak(false, $this->margeBottom); $this->pdf->setXY($this->defaultLeft, $this->defaultTop); $this->style->initStyle(); $this->style->resetStyle(); $this->style->value['width'] = $this->pdf->getW() - $this->defaultLeft - $this->defaultRight; $this->style->table = array(); // on en créé un sous HTML que l'on transforme en PDF // pour récupérer la hauteur // on extrait tout ce qui est contenu dans le FOOTER $sub = null; $this->CreateSubHTML($sub); $sub->parsing->code = $this->parsing->getLevel($this->parse_pos); $sub->MakeHTMLcode(); $this->pdf->setY($this->pdf->getH() - $sub->maxY - $this->defaultBottom - 0.01); $this->destroySubHTML($sub); $this->style->save(); $this->style->analyse('page_footer_sub1', $param); $this->style->setPosition(); $this->style->FontSet(); $this->setNewPositionForNewLine(); return true; } function c_PAGE_FOOTER_SUB1($param) { if ($this->forOneLine) return false; $this->style->load(); $this->style->value = $this->subSTATES['s']; $this->style->table = $this->subSTATES['t']; $this->pageMarges = $this->subSTATES['mp']; $this->margeLeft = $this->subSTATES['ml']; $this->margeRight = $this->subSTATES['mr']; $this->margeTop = $this->subSTATES['mt']; $this->margeBottom = $this->subSTATES['mb']; $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight); $this->pdf->SetAutoPageBreak(false, $this->margeBottom); $this->pdf->setXY($this->subSTATES['x'], $this->subSTATES['y']); $this->style->FontSet(); $this->maxH = 0; return true; }
Comme vous l'aurez remarqué j'ai seulement copié la balise page_footer en page_footer1.
Pour son utilisation il faut utiliser les balises <page_footer1>...</page_footer1> de cette facon:
<page> <page_header> ... </page_header> <page_footer> //celui ci sera utilisé partout sauf sur la première page ... </page_footer> <page_footer1> // appliqué uniquement a la première page .. </page_footer1> ... </page>
j'espère que ce bout de code servira a quelqu'un, et j'espère ne pas etre passé a coté de quelque chose (reprenez moi sinon)
Bonne journée