[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: PDF_card.class.php,v 1.11 2005/09/03 15:14:34 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/adherents/cartes/PDF_card.class.php,v $ 21 * 22 */ 23 24 /* Inspire de PDF_Label 25 * PDF_Label - PDF label editing 26 * @package PDF_Label 27 * @author Laurent PASSEBECQ <lpasseb@numericable.fr> 28 * @copyright 2003 Laurent PASSEBECQ 29 * disponible ici : http://www.fpdf.org/fr/script/script29.php 30 */ 31 32 //////////////////////////////////////////////////// 33 // PDF_Label 34 // 35 // Classe afin d'éditer au format PDF des étiquettes 36 // au format Avery ou personnalisé 37 // 38 // 39 // Copyright (C) 2003 Laurent PASSEBECQ (LPA) 40 // Basé sur les fonctions de Steve Dillon : steved@mad.scientist.com 41 // 42 //------------------------------------------------------------------- 43 // VERSIONS : 44 // 1.0 : Initial release 45 // 1.1 : + : Added unit in the constructor 46 // + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1) 47 // + : Added in the description of a label : 48 // font-size : defaut char size (can be changed by calling Set_Char_Size(xx); 49 // paper-size : Size of the paper for this sheet (thanx to Al Canton) 50 // metric : type of unit used in this description 51 // You can define your label properties in inches by setting metric to 'in' 52 // and printing in millimiter by setting unit to 'mm' in constructor. 53 // Added some labels : 54 // 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com 55 // 8600 : thanx to Kunal Walia : kunal@u.washington.edu 56 // + : Added 3mm to the position of labels to avoid errors 57 //////////////////////////////////////////////////// 58 59 /** 60 \file htdocs/adherents/cartes/PDF_card.class.php 61 \ingroup adherent 62 \brief Fichier de la classe permettant d'éditer au format PDF des étiquettes au format Avery ou personnalisé 63 \author Steve Dillon 64 \author Laurent Passebecq 65 \author Rodolphe Quiedville 66 \author Jean Louis Bergamo. 67 \version $Revision: 1.11 $ 68 */ 69 70 require_once(FPDF_PATH.'fpdf.php'); 71 72 73 /** 74 \class PDF_card 75 \brief Classe afin d'éditer au format PDF des étiquettes au format Avery ou personnalisé 76 */ 77 78 class PDF_card extends FPDF { 79 80 // Propriétés privées 81 var $_Avery_Name = ''; // Nom du format de l'étiquette 82 var $_Margin_Left = 0; // Marge de gauche de l'étiquette 83 var $_Margin_Top = 0; // marge en haut de la page avant la première étiquette 84 var $_X_Space = 0; // Espace horizontal entre 2 bandes d'étiquettes 85 var $_Y_Space = 0; // Espace vertical entre 2 bandes d'étiquettes 86 var $_X_Number = 0; // Nombre d'étiquettes sur la largeur de la page 87 var $_Y_Number = 0; // Nombre d'étiquettes sur la hauteur de la page 88 var $_Width = 0; // Largeur de chaque étiquette 89 var $_Height = 0; // Hauteur de chaque étiquette 90 var $_Char_Size = 10; // Hauteur des caractères 91 var $_Line_Height = 10; // Hauteur par défaut d'une ligne 92 var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values 93 var $_Metric_Doc = 'mm'; // Type of metric for the doc.. 94 95 var $_COUNTX = 1; 96 var $_COUNTY = 1; 97 var $_First = 1; 98 99 // Listing of labels size 100 var $_Avery_Labels = array ( 101 '5160'=>array('name'=>'5160', 102 'paper-size'=>'letter', 103 'metric'=>'mm', 104 'marginLeft'=>1.762, 105 'marginTop'=>10.7, 106 'NX'=>3, 107 'NY'=>10, 108 'SpaceX'=>3.175, 109 'SpaceY'=>0, 110 'width'=>66.675, 111 'height'=>25.4, 112 'font-size'=>8), 113 '5161'=>array('name'=>'5161', 114 'paper-size'=>'letter', 115 'metric'=>'mm', 116 'marginLeft'=>0.967, 117 'marginTop'=>10.7, 118 'NX'=>2, 119 'NY'=>10, 120 'SpaceX'=>3.967, 121 'SpaceY'=>0, 122 'width'=>101.6, 123 'height'=>25.4, 124 'font-size'=>8), 125 '5162'=>array('name'=>'5162', 126 'paper-size'=>'letter', 127 'metric'=>'mm', 128 'marginLeft'=>0.97, 129 'marginTop'=>20.224, 130 'NX'=>2, 131 'NY'=>7, 132 'SpaceX'=>4.762, 133 'SpaceY'=>0, 134 'width'=>100.807, 135 'height'=>35.72, 136 'font-size'=>8), 137 '5163'=>array('name'=>'5163', 138 'paper-size'=>'letter', 139 'metric'=>'mm', 140 'marginLeft'=>1.762, 141 'marginTop'=>10.7, 142 'NX'=>2, 143 'NY'=>5, 144 'SpaceX'=>3.175, 145 'SpaceY'=>0, 146 'width'=>101.6, 147 'height'=>50.8, 148 'font-size'=>8), 149 '5164'=>array('name'=>'5164', 150 'paper-size'=>'letter', 151 'metric'=>'in', 152 'marginLeft'=>0.148, 153 'marginTop'=>0.5, 154 'NX'=>2, 155 'NY'=>3, 156 'SpaceX'=>0.2031, 157 'SpaceY'=>0, 158 'width'=>4.0, 159 'height'=>3.33, 160 'font-size'=>12), 161 '8600'=>array('name'=>'8600', 162 'paper-size'=>'letter', 163 'metric'=>'mm', 164 'marginLeft'=>7.1, 165 'marginTop'=>19, 166 'NX'=>3, 167 'NY'=>10, 168 'SpaceX'=>9.5, 169 'SpaceY'=>3.1, 170 'width'=>66.6, 171 'height'=>25.4, 172 'font-size'=>8), 173 'L7163'=>array('name'=>'L7163', 174 'paper-size'=>'A4', 175 'metric'=>'mm', 176 'marginLeft'=>5, 177 'marginTop'=>15, 178 'NX'=>2, 179 'NY'=>7, 180 'SpaceX'=>25, 181 'SpaceY'=>0, 182 'width'=>99.1, 183 'height'=>38.1, 184 'font-size'=>10), 185 'FREELUG'=>array('name'=>'FREELUG', 186 'paper-size'=>'A4', 187 'metric'=>'mm', 188 'marginLeft'=>0, 189 'marginTop'=>0, 190 'NX'=>2, 191 'NY'=>8, 192 'SpaceX'=>0, 193 'SpaceY'=>0, 194 'width'=>105, 195 'height'=>38, 196 'font-size'=>10), 197 'CARD'=>array('name'=>'CARD', 198 'paper-size'=>'A4', 199 'metric'=>'mm', 200 'marginLeft'=>15, 201 'marginTop'=>15, 202 'NX'=>2, 203 'NY'=>5, 204 'SpaceX'=>0, 205 'SpaceY'=>0, 206 'width'=>85, 207 'height'=>54, 208 'font-size'=>10, 209 'logo1'=>'logo1.jpg', 210 'logo2'=>'logo2.jpg', 211 'fond'=>'fond.jpg') 212 ); 213 214 // convert units (in to mm, mm to in) 215 // $src and $dest must be 'in' or 'mm' 216 function _Convert_Metric ($value, $src, $dest) { 217 if ($src != $dest) { 218 $tab['in'] = 39.37008; 219 $tab['mm'] = 1000; 220 return $value * $tab[$dest] / $tab[$src]; 221 } else { 222 return $value; 223 } 224 } 225 226 // Give the height for a char size given. 227 function _Get_Height_Chars($pt) { 228 // Tableau de concordance entre la hauteur des caractères et de l'espacement entre les lignes 229 $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>4, 10=>5, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); 230 if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { 231 return $_Table_Hauteur_Chars[$pt]; 232 } else { 233 return 100; // There is a prob.. 234 } 235 } 236 237 function _Set_Format($format) { 238 $this->_Metric = $format['metric']; 239 $this->_Avery_Name = $format['name']; 240 $this->_Margin_Left = $this->_Convert_Metric ($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); 241 $this->_Margin_Top = $this->_Convert_Metric ($format['marginTop'], $this->_Metric, $this->_Metric_Doc); 242 $this->_X_Space = $this->_Convert_Metric ($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); 243 $this->_Y_Space = $this->_Convert_Metric ($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); 244 $this->_X_Number = $format['NX']; 245 $this->_Y_Number = $format['NY']; 246 $this->_Width = $this->_Convert_Metric ($format['width'], $this->_Metric, $this->_Metric_Doc); 247 $this->_Height = $this->_Convert_Metric ($format['height'], $this->_Metric, $this->_Metric_Doc); 248 $this->Set_Char_Size( $format['font-size']); 249 } 250 251 function PDF_card ($format, $posX=1, $posY=1, $unit='mm') { 252 if (is_array($format)) { 253 // Si c'est un format personnel alors on maj les valeurs 254 $Tformat = $format; 255 } else { 256 // Si c'est un format avery on stocke le nom de ce format selon la norme Avery. 257 // Permettra d'aller récupérer les valeurs dans le tableau _Avery_Labels 258 $Tformat = $this->_Avery_Labels[$format]; 259 } 260 261 parent::FPDF('P', $unit, $Tformat['paper-size']); 262 $this->SetMargins(0,0); 263 $this->SetAutoPageBreak(false); 264 265 $this->_Metric_Doc = $unit; 266 // Permet de commencer l'impression à l'étiquette désirée dans le cas où la page a déjà servie 267 if ($posX > 0) $posX--; else $posX=0; 268 if ($posY > 0) $posY--; else $posY=0; 269 $this->_COUNTX = $posX; 270 $this->_COUNTY = $posY; 271 $this->_Set_Format($Tformat); 272 } 273 274 //Méthode qui permet de modifier la taille des caractères 275 // Cela modiera aussi l'espace entre chaque ligne 276 function Set_Char_Size($pt) { 277 if ($pt > 3) { 278 $this->_Char_Size = $pt; 279 $this->_Line_Height = $this->_Get_Height_Chars($pt); 280 $this->SetFont('Arial','',$pt); 281 } 282 } 283 284 // On imprime une étiqette 285 function Add_PDF_card($texte,$header='',$footer='') { 286 // We are in a new page, then we must add a page 287 if (($this->_COUNTX ==0) and ($this->_COUNTY==0) and (!$this->_First==1)) { 288 $this->AddPage(); 289 } 290 $this->_First=0; 291 $_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space)); 292 $_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space)); 293 294 if ($this->_Avery_Name == "CARD") { 295 $Tformat=$this->_Avery_Labels["CARD"]; 296 //$this->_Pointille($_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,25); 297 $this->_Croix($_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,10); 298 if($Tformat['fond'] != '' and file_exists($Tformat['fond'])){ 299 $this->image($Tformat['fond'],$_PosX,$_PosY,$this->_Width,$this->_Height); 300 } 301 if($Tformat['logo1'] != '' and file_exists($Tformat['logo1'])){ 302 $this->image($Tformat['logo1'],$_PosX+$this->_Width-21,$_PosY+1,20,20); 303 } 304 if($Tformat['logo2'] != '' and file_exists($Tformat['logo2'])){ 305 $this->image($Tformat['logo2'],$_PosX+$this->_Width-21,$_PosY+25,20,20); 306 } 307 308 //$this->image('logo1.jpg',$_PosX+$this->_Width-21,$_PosY+1,20); 309 if ($header!=''){ 310 $this->SetXY($_PosX, $_PosY+1); 311 $this->Cell($this->_Width, $this->_Line_Height,$header,0,1,'C'); 312 } 313 $this->SetXY($_PosX+3, $_PosY+3+$this->_Line_Height); 314 $this->MultiCell($this->_Width, $this->_Line_Height, $texte); 315 if ($footer!=''){ 316 $this->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1); 317 $this->Cell($this->_Width, $this->_Line_Height,$footer,0,1,'C'); 318 } 319 320 }else{ 321 $this->SetXY($_PosX+3, $_PosY+3); 322 $this->MultiCell($this->_Width, $this->_Line_Height, $texte); 323 } 324 $this->_COUNTY++; 325 326 if ($this->_COUNTY == $this->_Y_Number) { 327 // Si on est en bas de page, on remonte le 'curseur' de position 328 $this->_COUNTX++; 329 $this->_COUNTY=0; 330 } 331 332 if ($this->_COUNTX == $this->_X_Number) { 333 // Si on est en bout de page, alors on repart sur une nouvelle page 334 $this->_COUNTX=0; 335 $this->_COUNTY=0; 336 } 337 } 338 339 function _Pointille($x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) 340 { 341 $this->SetLineWidth($epaisseur); 342 $longueur=abs($x1-$x2); 343 $hauteur=abs($y1-$y2); 344 if($longueur>$hauteur) { 345 $Pointilles=($longueur/$nbPointilles)/2; // taille des pointilles 346 } 347 else { 348 $Pointilles=($hauteur/$nbPointilles)/2; 349 } 350 for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { 351 for($j=$i;$j<=($i+$Pointilles);$j++) { 352 if($j<=($x2-1)) { 353 $this->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point 354 $this->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point 355 } 356 } 357 } 358 for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { 359 for($j=$i;$j<=($i+$Pointilles);$j++) { 360 if($j<=($y2-1)) { 361 $this->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point 362 $this->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point 363 } 364 } 365 } 366 } 367 368 /* 369 * Fonction realisant une croix aux 4 coins des cartes 370 */ 371 function _Croix($x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=5) 372 { 373 $this->SetLineWidth($epaisseur); 374 $lg=$taille/2; 375 // croix haut gauche 376 $this->Line($x1,$y1-$lg,$x1,$y1+$lg); 377 $this->Line($x1-$lg,$y1,$x1+$lg,$y1); 378 // croix bas gauche 379 $this->Line($x1,$y2-$lg,$x1,$y2+$lg); 380 $this->Line($x1-$lg,$y2,$x1+$lg,$y2); 381 // croix haut droit 382 $this->Line($x2,$y1-$lg,$x2,$y1+$lg); 383 $this->Line($x2-$lg,$y1,$x2+$lg,$y1); 384 // croix bas droit 385 $this->Line($x2,$y2-$lg,$x2,$y2+$lg); 386 $this->Line($x2-$lg,$y2,$x2+$lg,$y2); 387 388 } 389 } 390 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |