/app/vendors/html2pdf/html2pdf.class.php
PHP | 4302 lines | 2750 code | 560 blank | 992 comment | 403 complexity | af7fa387a21226aff0240c7c665bd32d MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Logiciel : HTML2PDF
- *
- * Convertisseur HTML => PDF, utilise fpdf de Olivier PLATHEY
- * Distribué sous la licence GPL.
- *
- * @author Laurent MINGUET <webmaster@spipu.net>
- * @version 3.21 - 05/05/2009
- */
-
- if (!defined('__CLASS_HTML2PDF__'))
- {
- define('__CLASS_HTML2PDF__', '3.21');
-
- // vous pouvez utiliser cette fonction de debug comme suit
- // pour voir le temps et la mémoire utilisés (sous linux) pour la conversion :
- // echo HTML2PDFgetTimerDebug();
- // $html2pdf->WriteHTML($content);
- // echo HTML2PDFgetTimerDebug();
- function HTML2PDFgetTimerDebug($debug=false)
- {
- global $TIMER_ACTION_LAST;
- list($usec, $sec) = explode(" ", microtime());
- $time = (float)$sec + (float)$usec;
- $mem = HTML2PDFgetMem();
-
- if (!$TIMER_ACTION_LAST)
- {
- if ($debug) $ret = null;
- else $ret = 'Debug : init'."<br />\n";
- }
- else
- {
- $aff_time = $time-$TIMER_ACTION_LAST[0];
- $aff_mem = $mem;
- if ($debug) $ret = array($aff_time, $aff_mem);
- else $ret = 'Timer : '.number_format($aff_time, 3, '.', '').'s - Memory used '.$aff_mem.' Ko'."<br />\n";
- }
- $TIMER_ACTION_LAST = array($time, $mem);
- return $ret;
- }
- function HTML2PDFgetMem() { return function_exists('memory_get_usage') ? floor(memory_get_usage()/1024) : 0; }
-
- require_once(dirname(__FILE__).'/_mypdf/mypdf.class.php'); // classe mypdf dérivé de fpdf de Olivier PLATHEY
- require_once(dirname(__FILE__).'/parsingHTML.class.php'); // classe de parsing HTML
- require_once(dirname(__FILE__).'/styleHTML.class.php'); // classe de gestion des styles
-
- global $HTML2PDF_TABLEAU; $HTML2PDF_TABLEAU = array(); // tableau global necessaire à la gestion des tables imbriquées
-
- class HTML2PDF
- {
- var $langue = 'fr'; // langue des messages
- var $sens = 'P'; // sens d'affichage Portrait ou Landscape
- var $format = 'A4'; // format de la page : A4, A3, ...
- var $background = array(); // informations sur le background
- var $testTDin1page = true; // activer le test de TD ne devant pas depasser une page
-
- var $style = null; // objet de style
- var $parsing = null; // objet de parsing
- var $parse_pos = 0; // position du parsing
- var $temp_pos = 0; // position temporaire pour multi tableau
-
- var $sub_html = null; // sous html
- var $sub_part = false; // indicateur de sous html
- var $isSubPart = false; // indique que le convertisseur courant est un sous html
-
- var $pdf = null; // objet PDF
- var $maxX = 0; // zone maxi X
- var $maxY = 0; // zone maxi Y
-
- var $FirstPage = true; // premier page
-
- var $defaultLeft = 0; // marges par default de la page
- var $defaultTop = 0;
- var $defaultRight = 0;
- var $defaultBottom = 0;
-
- var $margeLeft = 0; //marges réelles de la page
- var $margeTop = 0;
- var $margeRight = 0;
- var $margeBottom = 0;
- var $marges = array();
- var $Maxs = array();
-
- var $maxH = 0; // plus grande hauteur dans la ligne, pour saut de ligne à corriger
- var $inLink = ''; // indique si on est à l'interieur d'un lien
- var $lstAncre = array(); // liste des ancres détectées ou créées
- var $subHEADER = array(); // tableau des sous commandes pour faire l'HEADER
- var $subFOOTER = array(); // tableau des sous commandes pour faire le FOOTER
- var $subSTATES = array(); // tableau de sauvegarde de certains paramètres
- var $defLIST = array(); // tableau de sauvegarde de l'etat des UL et OL
-
- var $lstChamps = array(); // liste des champs
- var $lstSelect = array(); // options du select en cours
- var $previousCall = null; // dernier appel
- var $isInTfoot = false; // indique si on est dans un tfoot
- var $pageMarges = array(); // marges spécifiques dues aux floats
- var $isAfterFloat = false; // indique si on est apres un float
-
- /**
- * Constructeur
- *
- * @param string sens portrait ou landscape
- * @param string format A4, A5, ...
- * @param string langue : fr, en, it...
- * @param array marges par defaut, dans l'ordre (left, top, right, bottom)
- * @param boolean forcer la création de la premiere page, ne pas utiliser, c'est utilisé en interne pour la gestion des tableaux
- * @return null
- */
- function HTML2PDF($sens = 'P', $format = 'A4', $langue='fr', $marges = array(5, 5, 5, 8), $force_page = false)
- {
- // sauvegarde des paramètres
- $this->sens = $sens;
- $this->format = $format;
- $this->FirstPage = true;
- $this->langue = strtolower($langue);
- $this->setTestTdInOnePage(true);
-
- // chargement du fichier de langue
- $this->textLOAD($this->langue);
-
- // création de l' objet PDF
- $this->pdf = new MyPDF($sens, 'mm', $format);
-
- // initialisation des styles
- $this->style = new styleHTML($this->pdf);
- $this->style->FontSet();
- $this->defLIST = array();
-
- // initialisation du parsing
- $this->parsing = new parsingHTML();
- $this->sub_html = null;
- $this->sub_part = false;
-
- // initialisation des marges
- $this->setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]);
- $this->setMargins();
- $this->marges = array();
-
- // initialisation des champs de formulaire
- $this->lstChamps = array();
-
- // premier page forcée
- if ($force_page) $this->setNewPage($this->sens);
- }
-
- /**
- * activer ou desactiver le test de TD ne devant pas depasser une page
- *
- * @param boolean nouvel etat
- * @return boolean ancien etat
- */
- function setTestTdInOnePage($mode = true)
- {
- $old = $this->testTDin1page;
-
- $this->testTDin1page = $mode ? true : false;
-
- return $old;
- }
-
- /**
- * définir les marges par défault
- *
- * @param int en mm, marge left
- * @param int en mm, marge top
- * @param int en mm, marge right. si null, left=right
- * @param int en mm, marge bottom. si null, bottom=8
- * @return null
- */
- function setDefaultMargins($left, $top, $right = null, $bottom = null)
- {
- if ($right===null) $right = $left;
- if ($bottom===null) $bottom = 8;
-
- $this->defaultLeft = $this->style->ConvertToMM($left.'mm');
- $this->defaultTop = $this->style->ConvertToMM($top.'mm');
- $this->defaultRight = $this->style->ConvertToMM($right.'mm');
- $this->defaultBottom = $this->style->ConvertToMM($bottom.'mm');
- }
-
- /**
- * définir les marges réelles, fonctions de la balise page
- *
- * @return null
- */
- function setMargins()
- {
- $this->margeLeft = $this->defaultLeft + (isset($this->background['left']) ? $this->background['left'] : 0);
- $this->margeRight = $this->defaultRight + (isset($this->background['right']) ? $this->background['right'] : 0);
- $this->margeTop = $this->defaultTop + (isset($this->background['top']) ? $this->background['top'] : 0);
- $this->margeBottom = $this->defaultBottom + (isset($this->background['bottom']) ? $this->background['bottom'] : 0);
-
- $this->pdf->SetMargins($this->margeLeft, $this->margeTop, $this->margeRight);
- $this->pdf->cMargin = 0;
- $this->pdf->SetAutoPageBreak(false, $this->margeBottom);
- }
-
- /**
- * recuperer les positions x minimales et maximales en fonction d'une hauteur
- *
- * @param float y
- * @return array(float, float)
- */
- function getMargins($y)
- {
- $y = floor($y*100);
- $x = array($this->pdf->lMargin, $this->pdf->w-$this->pdf->rMargin);
-
- foreach($this->pageMarges as $m_y => $m_x)
- if ($m_y<=$y) $x = $m_x;
-
- return $x;
- }
-
- /**
- * ajouter une marge suite a un float
- *
- * @param string left ou right
- * @param float x1
- * @param float y1
- * @param float x2
- * @param float y2
- * @return null
- */
- function addMargins($float, $x1, $y1, $x2, $y2)
- {
- $old1 = $this->getMargins($y1);
- $old2 = $this->getMargins($y2);
- if ($float=='left') $old1[0] = $x2;
- if ($float=='right') $old1[1] = $x1;
-
- $y1 = floor($y1*100);
- $y2 = floor($y2*100);
-
- foreach($this->pageMarges as $m_y => $m_x)
- {
- if ($m_y<$y1) continue;
- if ($m_y>$y2) break;
- if ($float=='left' && $this->pageMarges[$m_y][0]<$x2) unset($this->pageMarges[$m_y]);
- if ($float=='right' && $this->pageMarges[$m_y][1]>$x1) unset($this->pageMarges[$m_y]);
- }
-
- $this->pageMarges[$y1] = $old1;
- $this->pageMarges[$y2] = $old2;
-
- ksort($this->pageMarges);
-
- $this->isAfterFloat = true;
- }
-
- /**
- * définir des nouvelles marges et sauvegarder les anciennes
- *
- * @param float marge left
- * @param float marge top
- * @param float marge right
- * @return null
- */
- function saveMargin($ml, $mt, $mr)
- {
- $this->marges[] = array('l' => $this->pdf->lMargin, 't' => $this->pdf->tMargin, 'r' => $this->pdf->rMargin, 'page' => $this->pageMarges);
- $this->pdf->SetMargins($ml, $mt, $mr);
-
- $this->pageMarges = array();
- $this->pageMarges[floor($mt*100)] = array($ml, $this->pdf->w-$mr);
- }
-
- /**
- * récuperer les dernières marches sauvées
- *
- * @return null
- */
- function loadMargin()
- {
- $old = array_pop($this->marges);
- if ($old)
- {
- $ml = $old['l'];
- $mt = $old['t'];
- $mr = $old['r'];
- $mP = $old['page'];
- }
- else
- {
- $ml = $this->margeLeft;
- $mt = 0;
- $mr = $this->margeRight;
- $mP = array($mt => array($ml, $this->pdf->w-$mr));
- }
-
- $this->pdf->SetMargins($ml, $mt, $mr);
- $this->pageMarges = $mP;
- }
-
- /**
- * permet d'ajouter une fonte.
- *
- * @param string nom de la fonte
- * @param string style de la fonte
- * @param string fichier de la fonte
- * @return null
- */
- function AddFont($family, $style='', $file='')
- {
- $this->pdf->AddFont($family, $style, $file);
- }
-
- /**
- * sauvegarder l'état actuelle des maximums
- *
- * @return null
- */
- function saveMax()
- {
- $this->Maxs[] = array($this->maxX, $this->maxY, $this->maxH);
- }
-
- /**
- * charger le dernier état sauvé des maximums
- *
- * @return null
- */
- function loadMax()
- {
- $old = array_pop($this->Maxs);
-
- if ($old)
- {
- $this->maxX = $old[0];
- $this->maxY = $old[1];
- $this->maxH = $old[2];
- }
- else
- {
- $this->maxX = 0;
- $this->maxY = 0;
- $this->maxH = 0;
- }
- }
-
- /**
- * afficher l'header contenu dans page_header
- *
- * @return null
- */
- function SetPageHeader()
- {
- if (!count($this->subHEADER)) return false;
-
- $OLD_parse_pos = $this->parse_pos;
- $OLD_parse_code = $this->parsing->code;
-
- $this->parse_pos = 0;
- $this->parsing->code = $this->subHEADER;
- $this->MakeHTMLcode();
-
- $this->parse_pos = $OLD_parse_pos;
- $this->parsing->code = $OLD_parse_code;
- }
-
- /**
- * afficher le footer contenu dans page_footer
- *
- * @return null
- */
- function SetPageFooter()
- {
- if (!count($this->subFOOTER)) return false;
-
- $OLD_parse_pos = $this->parse_pos;
- $OLD_parse_code = $this->parsing->code;
-
- $this->parse_pos = 0;
- $this->parsing->code = $this->subFOOTER;
- $this->MakeHTMLcode();
-
- $this->parse_pos = $OLD_parse_pos;
- $this->parsing->code = $OLD_parse_code;
- }
-
- /**
- * saut de ligne avec une hauteur spécifique
- *
- * @param float hauteur de la ligne
- * @return null
- */
- function setNewLine($h)
- {
- $this->pdf->Ln($h);
-
- list($lx, $rx) = $this->getMargins($this->pdf->y);
- $this->pdf->x=$lx;
- }
-
- /**
- * création d'une nouvelle page avec une orientation particuliere
- *
- * @param string sens P=portrait ou L=landscape
- * @param array tableau des propriétés du fond de la page
- * @return null
- */
- function setNewPage($orientation = '', $background = null)
- {
- /*
- if (!$this->FirstPage)
- {
- $info = debug_backtrace(); foreach($info as $k => $v) { unset($info[$k]['object']); unset($info[$k]['type']); unset($info[$k]['args']);}
- echo '<pre>'.print_r($info, true).'</pre><hr>';
- }
- */
- $this->FirstPage = false;
-
- $this->sens = $orientation ? $orientation : $this->sens;
- $this->background = $background!==null ? $background : $this->background;
- $this->maxY = 0;
- $this->maxX = 0;
-
- $this->pdf->lMargin = $this->defaultLeft;
- $this->pdf->rMargin = $this->defaultRight;
- $this->pdf->tMargin = $this->defaultTop;
- $this->pdf->AddPage($this->sens);
-
- if (!$this->sub_part && !$this->isSubPart)
- {
- if (is_array($this->background))
- {
- if (isset($this->background['color']) && $this->background['color'])
- {
- $this->pdf->SetFillColor($this->background['color'][0], $this->background['color'][1], $this->background['color'][2]);
- $this->pdf->Rect(0, 0, $this->pdf->w, $this->pdf->h, 'F');
- }
-
- if (isset($this->background['img']) && $this->background['img'])
- $this->pdf->Image($this->background['img'], $this->background['posX'], $this->background['posY'], $this->background['width']);
- }
-
- $this->SetPageHeader();
- $this->SetPageFooter();
- }
-
- $this->SetMargins();
- $this->pdf->y = $this->margeTop;
- list($lx, $rx) = $this->getMargins($this->pdf->y);
- $this->pdf->x=$lx;
- }
-
- /**
- * récupération du PDF
- *
- * @param string nom du fichier PDF
- * @param boolean destination
- * @return string contenu éventuel du pdf
- *
- *
- * Destination où envoyer le document. Le paramètre peut prendre les valeurs suivantes :
- * true : equivalent à I
- * false : equivalent à S
- * I : envoyer en inline au navigateur. Le plug-in est utilisé s'il est installé. Le nom indiqué dans name est utilisé lorsque l'on sélectionne "Enregistrer sous" sur le lien générant le PDF.
- * D : envoyer au navigateur en forçant le téléchargement, avec le nom indiqué dans name.
- * F : sauver dans un fichier local, avec le nom indiqué dans name (peut inclure un répertoire).
- * S : renvoyer le document sous forme de chaîne. name est ignoré.
- */
- function Output($name = '', $dest = false)
- {
- // nettoyage
- global $HTML2PDF_TABLEAU; $HTML2PDF_TABLEAU = array();
-
- // interpretation des paramètres
- if ($dest===false) $dest = 'I';
- if ($dest===true) $dest = 'S';
- if ($dest==='') $dest = 'I';
- if ($name=='') $name='document.pdf';
-
- // verification de la destination
- $dest = strtoupper($dest);
- if (!in_array($dest, array('I', 'D', 'F', 'S'))) $dest = 'I';
-
- // verification du nom
- if (strtolower(substr($name, -4))!='.pdf')
- {
- echo 'ERROR : The output document name "'.$name.'" is not a PDF name';
- exit;
- }
-
-
- return $this->pdf->Output($name, $dest);
- }
-
- /**
- * création d'un sous HTML2PDF pour la gestion des tableaux imbriqués
- *
- * @param HTML2PDF futur sous HTML2PDF passé en référence pour créatio
- * @return null
- */
- function CreateSubHTML(&$sub_html, $cellmargin=0)
- {
- // initialisation du sous objet
- $sub_html = new HTML2PDF(
- $this->sens,
- $this->format,
- $this->langue,
- array($this->defaultLeft,$this->defaultTop,$this->defaultRight,$this->defaultBottom),
- true
- );
- $sub_html->isSubPart = true;
- $sub_html->setTestTdInOnePage($this->testTDin1page);
-
- $sub_html->style->css = $this->style->css;
- $sub_html->style->css_keys = $this->style->css_keys;
- $sub_html->style->table = $this->style->table;
- $sub_html->style->value = $this->style->value;
- $sub_html->style->value['text-align'] = 'left';
- $sub_html->defLIST = $this->defLIST;
-
- // initialisation de la largeur
- if ($this->style->value['width'])
- {
- $marge = $cellmargin*2;
- $marge+= $this->style->value['padding']['l'] + $this->style->value['padding']['r'];
- $marge+= $this->style->value['border']['l']['width'] + $this->style->value['border']['r']['width'];
- $marge = $sub_html->pdf->w - $this->style->value['width'] + $marge;
- }
- else
- $marge = $this->margeLeft+$this->margeRight;
-
- $sub_html->saveMargin(0, 0, $marge);
-
- // initialisation des fontes
- $sub_html->pdf->fonts = &$this->pdf->fonts;
- $sub_html->pdf->FontFiles = &$this->pdf->FontFiles;
- $sub_html->pdf->diffs = &$this->pdf->diffs;
-
- // initialisation des positions et autre
- $sub_html->maxX = 0;
- $sub_html->maxY = 0;
- $sub_html->maxH = 0;
- $sub_html->pdf->setX(0);
- $sub_html->pdf->setY(0);
- $sub_html->style->FontSet();
- }
-
- /**
- * destruction d'un sous HTML2PDF pour la gestion des tableaux imbriqués
- *
- * @return null
- */
- function DestroySubHTML()
- {
-
- unset($this->sub_html);
- $this->sub_html = null;
- }
-
- /**
- * Convertir un nombre arabe en nombre romain
- *
- * @param integer nombre à convertir
- * @return string nombre converti
- */
- function listeArab2Rom($nb_ar)
- {
- $nb_b10 = array('I','X','C','M');
- $nb_b5 = array('V','L','D');
- $nb_ro = '';
-
- if ($nb_ar<1) return $nb_ar;
- if ($nb_ar>3999) return $nb_ar;
-
- for($i=3; $i>=0 ; $i--)
- {
- $chiffre=floor($nb_ar/pow(10,$i));
- if($chiffre>=1)
- {
- $nb_ar=$nb_ar-$chiffre*pow(10,$i);
- if($chiffre<=3)
- {
- for($j=$chiffre; $j>=1; $j--)
- {
- $nb_ro=$nb_ro.$nb_b10[$i];
- }
- }
- else if($chiffre==9)
- {
- $nb_ro=$nb_ro.$nb_b10[$i].$nb_b10[$i+1];
- }
- elseif($chiffre==4)
- {
- $nb_ro=$nb_ro.$nb_b10[$i].$nb_b5[$i];
- }
- else
- {
- $nb_ro=$nb_ro.$nb_b5[$i];
- for($j=$chiffre-5; $j>=1; $j--)
- {
- $nb_ro=$nb_ro.$nb_b10[$i];
- }
- }
- }
- }
- return $nb_ro;
- }
-
- /**
- * Ajouter un LI au niveau actuel
- *
- * @return null
- */
- function listeAddLi()
- {
- $this->defLIST[count($this->defLIST)-1]['nb']++;
- }
-
- function listeGetWidth() { return '7mm'; }
- function listeGetPadding() { return '1mm'; }
-
- /**
- * Recuperer le LI du niveau actuel
- *
- * @return string chaine à afficher
- */
- function listeGetLi()
- {
- $im = $this->defLIST[count($this->defLIST)-1]['img'];
- $st = $this->defLIST[count($this->defLIST)-1]['style'];
- $nb = $this->defLIST[count($this->defLIST)-1]['nb'];
- $up = (substr($st, 0, 6)=='upper-');
-
- if ($im) return array(false, false, $im);
-
- switch($st)
- {
- case 'none':
- return array('arial', true, ' ');
-
- case 'upper-alpha':
- case 'lower-alpha':
- $str = '';
- while($nb>26)
- {
- $str = chr(96+$nb%26).$str;
- $nb = floor($nb/26);
- }
- $str = chr(96+$nb).$str;
-
- return array('arial', false, ($up ? strtoupper($str) : $str).'.');
-
- case 'upper-roman':
- case 'lower-roman':
- $str = $this->listeArab2Rom($nb);
-
- return array('arial', false, ($up ? strtoupper($str) : $str).'.');
-
- case 'decimal':
- return array('arial', false, $nb.'.');
-
- case 'square':
- return array('zapfdingbats', true, chr(110));
-
- case 'circle':
- return array('zapfdingbats', true, chr(109));
-
- case 'disc':
- default:
- return array('zapfdingbats', true, chr(108));
- }
- }
-
- /**
- * Ajouter un niveau de liste
- *
- * @param string type de liste : ul, ol
- * @param string style de la liste
- * @return null
- */
- function listeAddLevel($type = 'ul', $style = '', $img = null)
- {
- if ($img)
- {
- if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match))
- $img = $match[1];
- else
- $img = null;
- }
- else
- $img = null;
-
- if (!in_array($type, array('ul', 'ol'))) $type = 'ul';
- if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = '';
-
- if (!$style)
- {
- if ($type=='ul') $style = 'disc';
- else $style = 'decimal';
- }
- $this->defLIST[count($this->defLIST)] = array('style' => $style, 'nb' => 0, 'img' => $img);
- }
-
- /**
- * Supprimer un niveau de liste
- *
- * @return null
- */
- function listeDelLevel()
- {
- if (count($this->defLIST))
- {
- unset($this->defLIST[count($this->defLIST)-1]);
- $this->defLIST = array_values($this->defLIST);
- }
- }
-
- /**
- * traitement d'un code HTML
- *
- * @param string code HTML à convertir
- * @param boolean afficher en pdf (false) ou en html (true)
- * @return null
- */
- function WriteHTML($html, $vue = false)
- {
- $html = str_replace('[[page_nb]]', '{nb}', $html);
-
- $html = str_replace('[[date_y]]', date('Y'), $html);
- $html = str_replace('[[date_m]]', date('m'), $html);
- $html = str_replace('[[date_d]]', date('d'), $html);
-
- $html = str_replace('[[date_h]]', date('H'), $html);
- $html = str_replace('[[date_i]]', date('i'), $html);
- $html = str_replace('[[date_s]]', date('s'), $html);
-
- // si on veut voir le résultat en HTML => on appelle la fonction
- if ($vue) $this->vueHTML($html);
-
- // sinon, traitement pour conversion en PDF :
- // parsing
- $this->sub_pdf = false;
- $this->style->readStyle($html);
- $this->parsing->setHTML($html);
- $this->parsing->parse();
- $this->MakeHTMLcode();
- }
-
- function MakeHTMLcode()
- {
- // pour chaque element identifié par le parsing
- for($this->parse_pos=0; $this->parse_pos<count($this->parsing->code); $this->parse_pos++)
- {
- // récupération de l'élément
- $todo = $this->parsing->code[$this->parse_pos];
-
- // si c'est une ouverture de tableau
- if (in_array($todo['name'], array('table', 'ul', 'ol')) && !$todo['close'])
- {
- // on va créer un sous HTML, et on va travailler sur une position temporaire
- $tag_open = $todo['name'];
-
- $this->sub_part = true;
- $this->temp_pos = $this->parse_pos;
-
- // pour tous les éléments jusqu'à la fermeture de la table afin de préparer les dimensions
- while(isset($this->parsing->code[$this->temp_pos]) && !($this->parsing->code[$this->temp_pos]['name']==$tag_open && $this->parsing->code[$this->temp_pos]['close']))
- {
- $this->loadAction($this->parsing->code[$this->temp_pos]);
- $this->temp_pos++;
- }
- if (isset($this->parsing->code[$this->temp_pos])) $this->loadAction($this->parsing->code[$this->temp_pos]);
- $this->sub_part = false;
- }
-
- // chargement de l'action correspondant à l'élément
- $this->loadAction($todo);
- }
- }
-
-
-
- /**
- * affichage en mode HTML du contenu
- *
- * @param string contenu
- * @return null
- */
- function vueHTML($content)
- {
- $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue01').' : $1<hr><div$1>', $content);
- $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue02').' : $1<hr><div$1>', $content);
- $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF::textGET('vue03').' : $1<hr><div$1>', $content);
- $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content);
- $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content);
- $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content);
-
- echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>'.HTML2PDF::textGET('vue04').' HTML</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
- </head>
- <body style="padding: 10px; font-size: 10pt;font-family: Arial;">
- '.$content.'
-
- </body>
- </html>';
- exit;
- }
-
- /**
- * chargement de l'action correspondante à un element de parsing
- *
- * @param array élément de parsing
- * @return null
- */
- function loadAction($row)
- {
- // nom de l'action
- $fnc = ($row['close'] ? 'c_' : 'o_').strtoupper($row['name']);
-
- // parametres de l'action
- $param = $row['param'];
-
- // si aucune page n'est créé, on la créé
- if ($fnc!='o_PAGE' && $this->FirstPage)
- {
- $this->setNewPage();
- }
-
- // lancement de l'action
- if (is_callable(array(&$this, $fnc)))
- {
- $this->{$fnc}($param);
- $this->previousCall = $fnc;
- }
- else
- {
- HTML2PDF::makeError(1, __FILE__, __LINE__, strtoupper($row['name']));
- }
- }
-
- /**
- * balise : PAGE
- * mode : OUVERTURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function o_PAGE($param)
- {
- $newPageSet= (!isset($param['pageset']) || $param['pageset']!='old');
-
- $this->maxH = 0;
- if ($newPageSet)
- {
- $this->subHEADER = array();
- $this->subFOOTER = array();
-
- // identification de l'orientation demandée
- $orientation = '';
- if (isset($param['orientation']))
- {
- $param['orientation'] = strtolower($param['orientation']);
- if ($param['orientation']=='p') $orientation = 'P';
- if ($param['orientation']=='portrait') $orientation = 'P';
-
- if ($param['orientation']=='l') $orientation = 'L';
- if ($param['orientation']=='paysage') $orientation = 'L';
- if ($param['orientation']=='landscape') $orientation = 'L';
- }
-
- // identification des propriétés du background
- $background = array();
- if (isset($param['backimg']))
- {
- $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // nom de l'image
- $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // position horizontale de l'image
- $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // position verticale de l'image
- $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // taille de l'image (100% = largueur de la feuille)
-
- // conversion du nom de l'image, en cas de paramètres en _GET
- $background['img'] = str_replace('&', '&', $background['img']);
- // conversion des positions
- if ($background['posX']=='left') $background['posX'] = '0%';
- if ($background['posX']=='center') $background['posX'] = '50%';
- if ($background['posX']=='right') $background['posX'] = '100%';
- if ($background['posY']=='top') $background['posY'] = '0%';
- if ($background['posY']=='middle') $background['posY'] = '50%';
- if ($background['posY']=='bottom') $background['posY'] = '100%';
-
-
- // si il y a une image de précisé
- if ($background['img'])
- {
- // est-ce que c'est une image ?
- $infos=@GetImageSize($background['img']);
- if (count($infos)>1)
- {
- // taille de l'image, en fonction de la taille spécifiée.
- $Wi = $this->style->ConvertToMM($background['width'], $this->pdf->w);
- $Hi = $Wi*$infos[1]/$infos[0];
-
- // récupération des dimensions et positions de l'image
- $background['width'] = $Wi;
- $background['posX'] = $this->style->ConvertToMM($background['posX'], $this->pdf->w - $Wi);
- $background['posY'] = $this->style->ConvertToMM($background['posY'], $this->pdf->h - $Hi);
- }
- else
- $background = array();
- }
- else
- $background = array();
- }
-
- // marges TOP et BOTTOM pour le texte.
- $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0';
- $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0';
- $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0';
- $background['right'] = isset($param['backright']) ? $param['backright'] : '0';
-
- if (preg_match('/^([0-9]*)$/isU', $background['top'])) $background['top'] .= 'mm';
- if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) $background['bottom'] .= 'mm';
- if (preg_match('/^([0-9]*)$/isU', $background['left'])) $background['left'] .= 'mm';
- if (preg_match('/^([0-9]*)$/isU', $background['right'])) $background['right'] .= 'mm';
-
- $background['top'] = $this->style->ConvertToMM($background['top'], $this->pdf->h);
- $background['bottom'] = $this->style->ConvertToMM($background['bottom'], $this->pdf->h);
- $background['left'] = $this->style->ConvertToMM($background['left'], $this->pdf->w);
- $background['right'] = $this->style->ConvertToMM($background['right'], $this->pdf->w);
-
- $res = false;
- $background['color'] = isset($param['backcolor']) ? $this->style->ConvertToRVB($param['backcolor'], $res) : null;
- if (!$res) $background['color'] = null;
-
- $this->style->save();
- $this->style->analyse('PAGE', $param);
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- $this->style->FontSet();
-
- // nouvelle page
- $this->setNewPage($orientation, $background);
-
- // footer automatique
- if (isset($param['footer']))
- {
- $lst = explode(';', $param['footer']);
- foreach($lst as $key => $val) $lst[$key] = trim(strtolower($val));
- $page = in_array('page', $lst);
- $date = in_array('date', $lst);
- $heure = in_array('heure', $lst);
- $form = in_array('form', $lst);
- }
- else
- {
- $page = null;
- $date = null;
- $heure = null;
- $form = null;
- }
- $this->pdf->SetMyFooter($page, $date, $heure, $form);
- }
- else
- {
- $this->style->save();
- $this->style->analyse('PAGE', $param);
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- $this->style->FontSet();
-
- $this->setNewPage();
- }
-
- }
-
- /**
- * balise : PAGE
- * mode : FERMETURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function c_PAGE($param)
- {
- $this->maxH = 0;
-
- $this->style->load();
- $this->style->FontSet();
- }
-
-
- function o_PAGE_HEADER($param)
- {
- $this->subHEADER = 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_header') $todo['name']='page_header_sub';
- $this->subHEADER[] = $todo;
- if (strtolower($todo['name'])=='page_header_sub' && $todo['close']) break;
- }
-
- $this->SetPageHeader();
- }
-
- function o_PAGE_FOOTER($param)
- {
- $this->subFOOTER = 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_footer') $todo['name']='page_footer_sub';
- $this->subFOOTER[] = $todo;
- if (strtolower($todo['name'])=='page_footer_sub' && $todo['close']) break;
- }
-
- $this->SetPageFooter();
- }
-
- function o_PAGE_HEADER_SUB($param)
- {
- $this->subSTATES = array();
- $this->subSTATES['x'] = $this->pdf->x;
- $this->subSTATES['y'] = $this->pdf->y;
- $this->subSTATES['s'] = $this->style->value;
- $this->subSTATES['t'] = $this->style->table;
- $this->subSTATES['ml'] = $this->pdf->lMargin;
- $this->subSTATES['mr'] = $this->pdf->rMargin;
- $this->subSTATES['mt'] = $this->pdf->tMargin;
- $this->subSTATES['mb'] = $this->pdf->bMargin;
-
- $this->pdf->x = $this->defaultLeft;
- $this->pdf->y = $this->defaultTop;
- $this->style->initStyle();
- $this->style->resetStyle();
- $this->style->value['width'] = $this->pdf->w - $this->defaultLeft - $this->defaultRight;
- $this->style->table = array();
- $this->pdf->lMargin = $this->defaultLeft;
- $this->pdf->rMargin = $this->defaultRight;
- $this->pdf->tMargin = $this->defaultTop;
- $this->pdf->bMargin = $this->defaultBottom;
- $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
-
- $this->style->save();
- $this->style->analyse('page_header_sub', $param);
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- $this->style->FontSet();
- }
-
- function c_PAGE_HEADER_SUB($param)
- {
- $this->style->load();
-
- $this->pdf->x = $this->subSTATES['x'];
- $this->pdf->y = $this->subSTATES['y'];
- $this->style->value = $this->subSTATES['s'];
- $this->style->table = $this->subSTATES['t'];
- $this->pdf->lMargin = $this->subSTATES['ml'];
- $this->pdf->rMargin = $this->subSTATES['mr'];
- $this->pdf->tMargin = $this->subSTATES['mt'];
- $this->pdf->bMargin = $this->subSTATES['mb'];
- $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
-
- $this->style->FontSet();
- }
-
- function o_PAGE_FOOTER_SUB($param)
- {
- $this->subSTATES = array();
- $this->subSTATES['x'] = $this->pdf->x;
- $this->subSTATES['y'] = $this->pdf->y;
- $this->subSTATES['s'] = $this->style->value;
- $this->subSTATES['t'] = $this->style->table;
- $this->subSTATES['ml'] = $this->pdf->lMargin;
- $this->subSTATES['mr'] = $this->pdf->rMargin;
- $this->subSTATES['mt'] = $this->pdf->tMargin;
- $this->subSTATES['mb'] = $this->pdf->bMargin;
-
- $this->pdf->x = $this->defaultLeft;
- $this->pdf->y = $this->defaultTop;
- $this->style->initStyle();
- $this->style->resetStyle();
- $this->style->value['width'] = $this->pdf->w - $this->defaultLeft - $this->defaultRight;
- $this->style->table = array();
- $this->pdf->lMargin = $this->defaultLeft;
- $this->pdf->rMargin = $this->defaultRight;
- $this->pdf->tMargin = $this->defaultTop;
- $this->pdf->bMargin = $this->defaultBottom;
- $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
-
- // 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;
- $res = $this->parsing->getLevel($this->parse_pos);
- $this->CreateSubHTML($sub);
- $sub->writeHTML($res[1]);
- $this->pdf->y = $this->pdf->h - $sub->maxY - $this->defaultBottom - 0.01;
- unset($sub);
-
- $this->style->save();
- $this->style->analyse('page_footer_sub', $param);
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- $this->style->FontSet();
- }
-
- function c_PAGE_FOOTER_SUB($param)
- {
- $this->style->load();
-
- $this->pdf->x = $this->subSTATES['x'];
- $this->pdf->y = $this->subSTATES['y'];
- $this->style->value = $this->subSTATES['s'];
- $this->style->table = $this->subSTATES['t'];
- $this->pdf->lMargin = $this->subSTATES['ml'];
- $this->pdf->rMargin = $this->subSTATES['mr'];
- $this->pdf->tMargin = $this->subSTATES['mt'];
- $this->pdf->bMargin = $this->subSTATES['mb'];
- $this->pdf->PageBreakTrigger = $this->pdf->h - $this->pdf->bMargin;
-
- $this->style->FontSet();
- }
-
- /**
- * balise : NOBREAK
- * mode : OUVERTURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function o_NOBREAK($param)
- {
- $this->maxH = 0;
- // on extrait tout ce qui est contenu dans le NOBREAK
- $res = $this->parsing->getLevel($this->parse_pos);
-
- // on en créé un sous HTML que l'on transforme en PDF
- // pour analyse les dimensions
- // et voir si ca rentre
- $sub = null;
- $this->CreateSubHTML($sub);
- $sub->writeHTML($res[1]);
-
- $y = $this->pdf->getY();
- if (
- $sub->maxY < ($this->pdf->h - $this->pdf->tMargin-$this->pdf->bMargin) &&
- $y + $sub->maxY>=($this->pdf->h - $this->pdf->bMargin)
- )
- $this->setNewPage();
- unset($sub);
- }
-
-
- /**
- * balise : NOBREAK
- * mode : FERMETURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function c_NOBREAK($param)
- {
- $this->maxH = 0;
-
- }
-
- /**
- * balise : DIV
- * mode : OUVERTURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function o_DIV($param, $other = 'div')
- {
- $this->style->save();
- $this->style->analyse($other, $param);
- $this->style->FontSet();
-
- $align_object = null;
- if ($this->style->value['margin-auto']) $align_object = 'center';
-
- $marge = array();
- $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
- $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
- $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
- $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
-
- // on extrait tout ce qui est contenu dans la DIV
- $res = $this->parsing->getLevel($this->parse_pos);
-
- // on en créé un sous HTML que l'on transforme en PDF
- // pour analyse les dimensions
- $w = 0; $h = 0;
- if (trim($res[1]))
- {
- $sub = null;
- $this->CreateSubHTML($sub);
- $sub->writeHTML($res[1]);
- $w = $sub->maxX;
- $h = $sub->maxY;
- unset($sub);
- }
-
- $w+= $marge['l']+$marge['r'];
- $h+= $marge['t']+$marge['b'];
-
- $this->style->value['width'] = max($w, $this->style->value['width']);
- $this->style->value['height'] = max($h, $this->style->value['height']);
-
- if (!$this->style->value['position'])
- {
- if (
- $this->style->value['width'] < ($this->pdf->w - $this->pdf->lMargin-$this->pdf->rMargin) &&
- $this->pdf->x + $this->style->value['width']>=($this->pdf->w - $this->pdf->rMargin)
- )
- $this->o_BR(array());
-
- if (
- $this->style->value['height'] < ($this->pdf->h - $this->pdf->tMargin-$this->pdf->bMargin) &&
- $this->pdf->y + $this->style->value['height']>=($this->pdf->h - $this->pdf->bMargin)
- )
- $this->setNewPage();
-
- // en cas d'alignement => correction
- $w = $this->style->value['width'];
- $old = isset($this->style->table[count($this->style->table)-1]) ? $this->style->table[count($this->style->table)-1] : $this->style->value;
- $parent_w = $old['width'] ? $old['width'] : $this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin;
-
- if ($parent_w>$w)
- {
- if ($align_object=='center') $this->pdf->x = $this->pdf->x + ($parent_w-$w)*0.5;
- else if ($align_object=='right') $this->pdf->x = $this->pdf->x + $parent_w-$w;
- }
-
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- }
- else
- {
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- $this->saveMax();
- $this->saveX = 0;
- $this->saveY = 0;
- $this->saveH = 0;
- }
-
- // initialisation du style des bordures de la premiere partie de tableau
- $this->Rectangle(
- $this->style->value['x'],
- $this->style->value['y'],
- $this->style->value['width'],
- $this->style->value['height'],
- $this->style->value['border'],
- $this->style->value['padding'],
- 0,
- $this->style->value['background']
- );
-
-
- $marge = array();
- $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
- $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
- $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
- $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
-
- $this->style->value['width'] = $this->style->value['width']-$marge['l']-$marge['r'];
- $this->style->value['height'] = $this->style->value['height']-$marge['r']-$marge['b'];
-
- // limitation des marges aux dimensions de la div
- $mL = $this->style->value['x']+$marge['l'];
- $mR = $this->pdf->w - $mL - $this->style->value['width'];
- $this->saveMargin($mL, 0, $mR);
-
- // positionnement en fonction
- $h_corr = $this->style->value['height'];
- $h_reel = $h-$marge['b']-$marge['t'];
- switch($this->style->value['vertical-align'])
- {
- case 'bottom':
- $y_corr = $h_corr-$h_reel;
- break;
-
- case 'middle':
- $y_corr = ($h_corr-$h_reel)*0.5;
- break;
-
- case 'top':
- default:
- $y_corr = 0;
- break;
- }
-
- $this->pdf->setX($this->style->value['x']+$marge['l']);
- $this->pdf->setY($this->style->value['y']+$marge['t']+$y_corr);
-
- }
- function o_BLOCKQUOTE($param) { $this->o_DIV($param, 'blockquote'); }
-
- /**
- * balise : DIV
- * mode : FERMETURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function c_DIV($param)
- {
- $marge = array();
- $marge['l'] = $this->style->value['border']['l']['width'] + $this->style->value['padding']['l']+0.03;
- $marge['r'] = $this->style->value['border']['r']['width'] + $this->style->value['padding']['r']+0.03;
- $marge['t'] = $this->style->value['border']['t']['width'] + $this->style->value['padding']['t']+0.03;
- $marge['b'] = $this->style->value['border']['b']['width'] + $this->style->value['padding']['b']+0.03;
-
- $x = $this->style->value['x'];
- $y = $this->style->value['y'];
- $w = $this->style->value['width']+$marge['l']+$marge['r'];
- $h = $this->style->value['height']+$marge['t']+$marge['b'];
-
- // correction pour les margins
- $w+= $this->style->value['margin']['r'];
- $h+= $this->style->value['margin']['b'];
-
- if ($this->style->value['position']!='absolute')
- {
- // position
- $this->pdf->x = $x+$w;
- $this->pdf->y = $y;
-
- // position MAX
- $this->maxX = max($this->maxX, $x+$w);
- $this->maxY = max($this->maxY, $y+$h);
- $this->maxH = max($this->maxH, $h);
- }
- else
- {
- // position
- $this->pdf->x = $this->style->value['xc'];
- $this->pdf->y = $this->style->value['yc'];
-
- $this->loadMax();
- }
-
- $block = ($this->style->value['display']!='inline' && $this->style->value['position']!='absolute');
-
- $this->style->load();
- $this->style->FontSet();
- $this->loadMargin();
-
- if ($block) $this->o_BR(array());
- }
- function c_BLOCKQUOTE($param) { $this->c_DIV($param); }
-
- /**
- * balise : BARCODE
- * mode : OUVERTURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function o_BARCODE($param)
- {
-
- $lst_barcode = array(
- 'EAN13' => '0.35mm',
- 'UPC_A' => '0.35mm',
- 'CODE39' => '1.00mm',
- );
- if (isset($param['type'])) $param['type'] = strtoupper($param['type']);
-
- if (!isset($param['type']) || !isset($lst_barcode[$param['type']])) $param['type']=='CODE39';
- if (!isset($param['value'])) $param['value'] = 0;
- if (!isset($param['bar_w'])) $param['bar_w'] = $lst_barcode[$param['type']];
- if (!isset($param['bar_h'])) $param['bar_h'] = '10mm';
-
- if (!isset($param['style']['color'])) $param['style']['color'] = '#000000';
- $param['style']['background-color'] = $param['style']['color'];
-
- $this->style->save();
- $this->style->analyse('barcode', $param);
- $this->style->setPosition($this->pdf->x, $this->pdf->y);
- $this->style->FontSet();
-
-
- $x = $this->pdf->getX();
- $y = $this->pdf->getY();
- $w = $this->style->ConvertToMM($param['bar_w']);
- $h = $this->style->ConvertToMM($param['bar_h']);
-
- $infos = $this->pdf->{'BARCODE_'.$param['type']}($x, $y, $param['value'], $h, $w);
-
- // position maximale globale
- $this->maxX = max($this->maxX, $x+$infos[0]);
- $this->maxY = max($this->maxY, $y+$infos[1]);
- $this->maxH = max($this->maxH, $infos[1]);
-
- $this->pdf->setX($x+$infos[0]);
-
- $this->style->load();
- $this->style->FontSet();
- }
-
- /**
- * balise : BARCODE
- * mode : FERMETURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function c_BARCODE($param)
- {
- // completement inutile
- }
-
- /**
- * balise : BOOKMARK
- * mode : OUVERTURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function o_BOOKMARK($param)
- {
- $titre = isset($param['title']) ? trim($param['title']) : '';
- $level = isset($param['level']) ? floor($param['level']) : 0;
-
- if ($level<0) $level = 0;
- if ($titre) $this->pdf->Bookmark($titre, $level, -1);
- }
-
- /**
- * balise : BOOKMARK
- * mode : FERMETURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function c_BOOKMARK($param)
- {
- // completement inutile
- }
-
- /**
- * balise : WRITE
- * mode : OUVERTURE
- *
- * @param array paramètres de l'élément de parsing
- * @return null
- */
- function o_WRITE($param)
- {
- $fill = false; //($this->style->value['background']['color']!=null);
-
- // récupération du texte à écrire, et conversion
- $txt = $param['txt'];
- $txt = str_replace('€', '€', $txt);
-
- if ($this->isAfterFloat)
- {
- $txt = preg_replace('/^([\s]*)([^\s])/isU', '$2', $txt);
- $this->isAfterFloat = false;
- }
-
- $txt = html_entity_decode($txt, ENT_QUOTES, 'ISO-8859-15');
- // $txt = utf8_decode(html_entity_decode($txt, ENT_QUOTES, 'UTF-8'));
-
- $txt = str_replace('[[page_cu]]', $this->pdf->PageNo(), $txt);
-
- // tailles du texte
- $h = 1.08*$this->style->value['font-size'];
- $dh = $h*$this->style->value['mini-decal'];
-
- $w = $this->pdf->GetStringWidth($txt);
-
- // identification de l'alignement
- $align = 'L';
- if ($this->style->value['text-align']!='left')
- {
- $w = $this->style->value['width'];
- if ($this->style->value['text-align']=='center') $align = 'C';
- if ($this->style->value['text-align']=='right') $align = 'R';
- }
-
- $maxX = 0; // plus grande largeur du texte apres retour à la ligne
- $x = $this->pdf->getX(); // position du texte
- $y = $this->pdf->getY();
- $w = $this->pdf->GetStringWidth($txt); // largeur du texte
- list($left, $right) = $this->getMargins($y); // marges autorisees
- $nb = 0; // nbr de lignes découpées
-
- // tant que ca ne rentre pas sur la ligne et qu'on a du texte => on découpe
- while($x+$w>$right && $x<$right && strlen($txt))
- {
- // liste des mots
- $lst = explode(' ', $txt);
-
- // trouver une phrase qui rentre dans la largeur, en ajoutant les mots 1 à 1
- $i=0;
- $old = '';
- $str = $lst[0];
- while(($x+$this->pdf->GetStringWidth($str))<=$right)
- {
- unset($lst[$i]);
- $old = $str;
-
- $i++;
- $str.= ' '.$lst[$i];
- }
- $str = $old;
-
- // si rien de rentre, et que le premier mot ne rentre de toute facon pas dans une ligne, on le force...
- if ($i==0 && (($left+$this->pdf->GetStringWidth($lst[0]))>=$right))
- {
- $str = $lst[0];
- unset($lst[0]);
- }
-
- // récupération des mots restant, et calcul de la largeur
- $txt = implode(' ', $lst);
- $w = $this->pdf->GetStringWidth($str);
-
- // ecriture du bout de phrase extrait et qui rentre
- $wc = ($align=='L' ? $w : $this->style->value['width']);
- if ($right - $left<$wc) $wc = $right - $left;
- $this->pdf->Cell($wc, $h+$dh, $str, 0, 0, $align, $fill, $this->inLink);
- $this->maxH = max($this->maxH, $this->style->getLineHeight());
-
- // détermination de la largeur max
- $maxX = max($maxX, $this->pdf->getX());
-
- // nouvelle position et nouvelle largeur pour la boucle
- $w = $this->pdf->GetStringWidth($txt);
- $y = $this->pdf->getY();
- $x = $this->pdf->getX();
-
- // si il reste du text à afficher
- if (strlen($txt))
- {
- // retour à la ligne
- $this->o_BR(array('style' => ''));
-
- $y = $this->pdf->getY();
- $x = $this->pdf->getX();
-
- // si la prochaine ligne ne rentre pas dans la page => nouvelle page
- if ($y + $h>$this->pdf->h - $this->pdf->bMargin) $this->setNewPage();
-
- // ligne suplémentaire. au bout de 1000 : trop long => erreur
- $nb++;
- if ($nb>1000) HTML2PDF::makeError(2, __FILE__, __LINE__, array($txt, $right-$left, $this->pdf->GetStringWidth($txt)));
-
- list($left, $right) = $this->getMargins($y); // marges autorisees
- }
- }
-
- // si il reste du text apres découpe, c'est qu'il rentre direct => on l'affiche
- if (strlen($txt))
- {
- $this->pdf->Cell(($align=='L' ? $w : $this->style->value['width']), $h+$dh, $txt, 0, 0, $align, $fill, $this->inLink);
- $this->maxH = max($this->maxH, $this->style->getLineHeight());
- }
-
- // détermination des positions MAX
- $maxX = max($maxX, $this->pdf->getX());
- $maxY = $this->pdf->getY()+$h;
-
- // position maximale globale
- $this->maxX = max($this->maxX, $maxX);
- $this->maxY = max($this->maxY, $maxY);
- }
-
- /**
- * tracer une image
- *
- * @param string nom du fichier source
- * @return null
- */
- function Image($src, $sub_li=false)
- {
- // est-ce que c'est une image ?
- $infos=@GetImageSize($src);
-
- if (count($infos)<2)
- {
- HTML2PDF::makeError(6, __FILE__, __LINE__, $src);
- return false;
- }
-
- // récupération des dimensions dans l'unité du PDF
- $wi = $infos[0]/$this->pdf->k;
- $hi = $infos[1]/$this->pdf->k;
-
- // détermination des dimensions d'affichage en fonction du style
- if ($this->style->value['width'] && $this->style->value['height'])
- {
- $w = $this->style->value['width'];
- $h = $this->style->value['height'];
- }
- else if ($this->style->value['width'])
- {
- $w = $this->style->value['width'];
- $h = $hi*$w/$wi;
-
- }
- else if ($this->style->value['height'])
- {
- $h = $this->style->value['height'];
- $w = $wi*$h/$hi;
- }
- else
- {
- $w = 72./96.*$wi;
- $h = 72./96.*$hi;
- }
-
- // detection du float
- $float = $this->style->getFloat();
- if ($float && $this->maxH) $this->o_BR(array());
-
- // position d'affichage
- $x = $this->pdf->getX();
- $y = $this->pdf->getY();
-
- // si l'image ne rentre pas dans la page => nouvelle page
- if ($y + $h>$this->pdf->h - $this-…
Large files files are truncated, but you can click here to view the full file