<?php
/*
----------------------------------------------------------------------
SYGAL - Systme de gestion d'association libre
Copyright (C) 2003 by the INDEPNET Development Team.
http://indepnet.net/
----------------------------------------------------------------------
LICENSE
This file is part of SYGAL.
SYGAL is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
SYGAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SYGAL; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
----------------------------------------------------------------------
Original Author of file: Bazile Lebeau et Dolans Jean-Mathieu
Purpose of file:
----------------------------------------------------------------------
*Inspir de pdfcards
* Auteurs Rodolphe Quiedeville <hide@address.com>
* Jean-Louis Bergamo <hide@address.com>
* de Dolibarr : http://www.dolibarr.com
*/
/* Inspire de PDF_Label
* PDF_Label - PDF label editing
* @package PDF_Label
* @author Laurent PASSEBECQ <hide@address.com>
* @copyright 2003 Laurent PASSEBECQ
* disponible ici : http://www.fpdf.org/fr/script/script29.php
*/
////////////////////////////////////////////////////
// PDF_Label
//
// Classe afin d'diter au format PDF des tiquettes
// au format Avery ou personnalis
//
//
// Copyright (C) 2003 Laurent PASSEBECQ (LPA)
// Bas sur les fonctions de Steve Dillon : hide@address.com
//
//-------------------------------------------------------------------
////////////////////////////////////////////////////
require_once('fpdf.php');
class PDF_card extends FPDF {
// Proprits prives
var $_Avery_Name = ''; // Nom du format de l'tiquette
var $_Margin_Left = 0; // Marge de gauche de l'tiquette
var $_Margin_Top = 0; // marge en haut de la page avant la premire tiquette
var $_X_Space = 0; // Espace horizontal entre 2 bandes d'tiquettes
var $_Y_Space = 0; // Espace vertical entre 2 bandes d'tiquettes
var $_X_Number = 0; // Nombre d'tiquettes sur la largeur de la page
var $_Y_Number = 0; // Nombre d'tiquettes sur la hauteur de la page
var $_Width = 0; // Largeur de chaque tiquette
var $_Height = 0; // Hauteur de chaque tiquette
var $Logo_Width = 40; // Largeur de chaque tiquette
var $Logo_Height = 20; // Hauteur de chaque tiquette
var $_Char_Size = 10; // Hauteur des caractres
var $_Line_Height = 10; // Hauteur par dfaut d'une ligne
var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values
var $_Metric_Doc = 'mm'; // Type of metric for the doc..
var $_COUNTX = 1;
var $_COUNTY = 1;
var $_First = 1;
var $_Point = 1;
var $_Cross = 1;
var $_FontColor = "#797f79";
var $_Font = "Arial";
var $_FontSize = "12";
var $_FontStyle = 'B';
var $_BackgroundImage = "";
var $_LogoImage = "";
// Listing of labels size
var $_Avery_Labels = array (
'5160'=>array('name'=>'5160',
'paper-size'=>'letter',
'metric'=>'mm',
'marginLeft'=>1.762,
'marginTop'=>10.7,
'NX'=>3,
'NY'=>10,
'SpaceX'=>3.175,
'SpaceY'=>0,
'width'=>66.675,
'height'=>25.4,
'font-size'=>8),
'5161'=>array('name'=>'5161',
'paper-size'=>'letter',
'metric'=>'mm',
'marginLeft'=>0.967,
'marginTop'=>10.7,
'NX'=>2,
'NY'=>10,
'SpaceX'=>3.967,
'SpaceY'=>0,
'width'=>101.6,
'height'=>25.4,
'font-size'=>8),
'5162'=>array('name'=>'5162',
'paper-size'=>'letter',
'metric'=>'mm',
'marginLeft'=>0.97,
'marginTop'=>20.224,
'NX'=>2,
'NY'=>7,
'SpaceX'=>4.762,
'SpaceY'=>0,
'width'=>100.807,
'height'=>35.72,
'font-size'=>8),
'5163'=>array('name'=>'5163',
'paper-size'=>'letter',
'metric'=>'mm',
'marginLeft'=>1.762,
'marginTop'=>10.7,
'NX'=>2,
'NY'=>5,
'SpaceX'=>3.175,
'SpaceY'=>0,
'width'=>101.6,
'height'=>50.8,
'font-size'=>8),
'5164'=>array('name'=>'5164',
'paper-size'=>'letter',
'metric'=>'in',
'marginLeft'=>0.148,
'marginTop'=>0.5,
'NX'=>2,
'NY'=>3,
'SpaceX'=>0.2031,
'SpaceY'=>0,
'width'=>4.0,
'height'=>3.33,
'font-size'=>12),
'8600'=>array('name'=>'8600',
'paper-size'=>'letter',
'metric'=>'mm',
'marginLeft'=>7.1,
'marginTop'=>15,
'NX'=>3,
'NY'=>10,
'SpaceX'=>3.5,
'SpaceY'=>4.1,
'width'=>66.6,
'height'=>25.4,
'font-size'=>8),
'L7163'=>array('name'=>'L7163',
'paper-size'=>'A4',
'metric'=>'mm',
'marginLeft'=>4,
'marginTop'=>15,
'NX'=>2,
'NY'=>7,
'SpaceX'=>5,
'SpaceY'=>1,
'width'=>99.1,
'height'=>38.1,
'font-size'=>10),
'CARD'=>array('name'=>'CARD',
'paper-size'=>'A4',
'metric'=>'mm',
'marginLeft'=>10,
'marginTop'=>5,
'NX'=>2,
'NY'=>5,
'SpaceX'=>2,
'SpaceY'=>4,
'width'=>90,
'height'=>55,
'font-size'=>10)
);
// convert units (in to mm, mm to in)
// $src and $dest must be 'in' or 'mm'
function _Convert_Metric ($value, $src, $dest) {
if ($src != $dest) {
$tab['in'] = 39.37008;
$tab['mm'] = 1000;
if ($tab[$src]!=0)
return $value * $tab[$dest] / $tab[$src];
else
return $value;
} else {
return $value;
}
}
// Give the height for a char size given.
function _Get_Height_Chars($pt) {
// Tableau de concordance entre la hauteur des caractres et de l'espacement entre les lignes
$_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);
if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
return $_Table_Hauteur_Chars[$pt];
} else {
return 100; // There is a prob..
}
}
function html2rgb($color)
{
// gestion du #...
if (substr($color,0,1)=="#") $color=substr($color,1,6);
$tablo[0] = hexdec(substr($color, 0, 2));
$tablo[1] = hexdec(substr($color, 2, 2));
$tablo[2] = hexdec(substr($color, 4, 2));
return $tablo;
}
function _Set_FontColor($color) {
$rgb=$this->html2rgb($color);
$this->_FontColor="$rgb[0],$rgb[1],$rgb[2]";
}
function _Set_Font($ft) {
$this->_Font = $ft;
}
function _Set_FontStyle($ft) {
if ($ft=='N') $ft='';
$this->_FontStyle = $ft;
}
function _Set_Char_Size($ft) {
$this->_FontSize = $ft;
}
function _Set_Point($pt) {
$this->_Point = $pt;
}
function _Set_Cross($cross) {
$this->_Cross = $cross;
}
function _Set_BackgroundImage($ft) {
$this->_BackgroundImage = $ft;
}
function _Set_LogoImage($ft) {
$this->_LogoImage = $ft;
}
function _Apply_Font_Attr() {
$this->Set_Char_Size($this->_FontSize);
$this->SetFont($this->_Font,$this->_FontStyle,$this->_FontSize);
$tab=split(",",$this->_FontColor);
$this->SetTextColor($tab[0],$tab[1],$tab[2]);
}
function _Set_Format($format) {
$this->_Metric = $format['metric'];
$this->_Avery_Name = $format['name'];
$this->_Margin_Left = $this->_Convert_Metric ($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
$this->_Margin_Top = $this->_Convert_Metric ($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
$this->_X_Space = $this->_Convert_Metric ($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
$this->_Y_Space = $this->_Convert_Metric ($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
$this->_X_Number = $format['NX'];
$this->_Y_Number = $format['NY'];
$this->_Width = $this->_Convert_Metric ($format['width'], $this->_Metric, $this->_Metric_Doc);
$this->_Height = $this->_Convert_Metric ($format['height'], $this->_Metric, $this->_Metric_Doc);
}
function PDF_card ($format, $posX=1, $posY=1, $unit='mm') {
if (is_array($format)) {
// Si c'est un format personnel alors on maj les valeurs
$Tformat = $format;
} else {
// Si c'est un format avery on stocke le nom de ce format selon la norme Avery.
// Permettra d'aller rcuprer les valeurs dans le tableau _Avery_Labels
$Tformat = $this->_Avery_Labels[$format];
}
parent::FPDF('P', $unit, $Tformat['paper-size']);
$this->SetMargins(0,0);
$this->SetAutoPageBreak(false);
$this->_Metric_Doc = $unit;
// Permet de commencer l'impression l'tiquette dsire dans le cas o la page a dj servie
if ($posX > 0) $posX--; else $posX=0;
if ($posY > 0) $posY--; else $posY=0;
$this->_COUNTX = $posX;
$this->_COUNTY = $posY;
$this->_Set_Format($Tformat);
}
//Mthode qui permet de modifier la taille des caractres
// Cela modiera aussi l'espace entre chaque ligne
function Set_Char_Size($pt) {
if ($pt > 3) {
$this->_Char_Size = $pt;
$this->_Line_Height = $this->_Get_Height_Chars($pt);
}
}
// On imprime une tiqette
function Add_PDF_card($texte,$header='',$footer='') {
// We are in a new page, then we must add a page
if (($this->_COUNTX ==0) and ($this->_COUNTY==0) and (!$this->_First==1)) {
$this->AddPage();
}
$this->_First=0;
$_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space));
$_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space));
if ($this->_Point) $this->_Pointille($_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,25);
if ($this->_Cross) $this->_Croix($_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,10);
if($this->_BackgroundImage!= '' and file_exists($this->_BackgroundImage)){
$this->image($this->_BackgroundImage,$_PosX,$_PosY,$this->_Width,$this->_Height);
}
if($this->_LogoImage != '' and file_exists($this->_LogoImage)){
$this->image($this->_LogoImage,$_PosX+$this->_Width-40,$_PosY+1,40,20);
}
if ($header!=''){
$this->SetXY($_PosX, $_PosY+1);
$this->Cell($this->_Width, $this->_Line_Height,$header,0,1,'C');
}
$this->SetXY($_PosX+3, $_PosY+3+$this->_Line_Height);
$this->MultiCell($this->_Width, $this->_Line_Height, $texte);
if ($footer!=''){
$this->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1);
$this->Cell($this->_Width, $this->_Line_Height,$footer,0,1,'C');
}
$this->_COUNTY++;
if ($this->_COUNTY == $this->_Y_Number) {
// Si on est en bas de page, on remonte le 'curseur' de position
$this->_COUNTX++;
$this->_COUNTY=0;
}
if ($this->_COUNTX == $this->_X_Number) {
// Si on est en bout de page, alors on repart sur une nouvelle page
$this->_COUNTX=0;
$this->_COUNTY=0;
}
}
function _Pointille($x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15)
{
$this->SetLineWidth($epaisseur);
$longueur=abs($x1-$x2);
$hauteur=abs($y1-$y2);
if($longueur>$hauteur) {
$Pointilles=($longueur/$nbPointilles)/2; // taille des pointilles
}
else {
$Pointilles=($hauteur/$nbPointilles)/2;
}
for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
for($j=$i;$j<=($i+$Pointilles);$j++) {
if($j<=($x2-1)) {
$this->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point
$this->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point
}
}
}
for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
for($j=$i;$j<=($i+$Pointilles);$j++) {
if($j<=($y2-1)) {
$this->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point
$this->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point
}
}
}
}
/*
* Fonction realisant une croix aux 4 coins des cartes
*/
function _Croix($x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=5)
{
$this->SetLineWidth($epaisseur);
$lg=$taille/2;
// croix haut gauche
$this->Line($x1,$y1-$lg,$x1,$y1+$lg);
$this->Line($x1-$lg,$y1,$x1+$lg,$y1);
// croix bas gauche
$this->Line($x1,$y2-$lg,$x1,$y2+$lg);
$this->Line($x1-$lg,$y2,$x1+$lg,$y2);
// croix haut droit
$this->Line($x2,$y1-$lg,$x2,$y1+$lg);
$this->Line($x2-$lg,$y1,$x2+$lg,$y1);
// croix bas droit
$this->Line($x2,$y2-$lg,$x2,$y2+$lg);
$this->Line($x2-$lg,$y2,$x2+$lg,$y2);
}
#$imagem - source of image
##$dpi - resolution to convert E.g.: 72dpi or 300dpi
#
function px2cm($image, $dpi) {
#Create a new image from file or URL
$img = ImageCreateFromJpeg($image);
#Get image width / height
$x = ImageSX($img);
$y = ImageSY($img);
#Convert to centimeter
$h = $x * 2.54 / $dpi;
$l = $y * 2.54 / $dpi;
#Format a number with grouped thousands
$h = number_format($h, 2, ',', ' ');
$l = number_format($l, 2, ',', ' ');
#add size unit
$px2cm[] = $h."cm";
$px2cm[] = $l."cm";
#return array w values
#$px2cm[0] = X
#$px2cm[1] = Y
return $px2cm;
}
}
?>