5,6 → 5,7 |
require_once('tcpdf_config.php'); |
require_once('tcpdf/tcpdf.php'); |
|
set_time_limit(6); |
Class GenerateurPDF { |
|
public $pdf; |
39,10 → 40,13 |
// $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); |
$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM); |
|
$pdf->SetFont('times', '', 12); |
$pdf->SetFont('times', '', 11); |
$pdf->setCellPaddings(1, 1, 1, 1); |
$pdf->setCellMargins(1, 1, 1, 1); |
|
$pdf->AddPage(); |
$pdf->setEqualColumns(2); |
|
$this->pdf = $pdf; |
} |
|
50,27 → 54,25 |
|
function export($obs) { |
$pdf = &$this->pdf; |
$pdf->AddPage(); |
$pdf->setEqualColumns(2); |
|
$i = 0; |
while($i < count($obs)) { |
$pdf->selectColumn(0); |
// Multicell test |
$this->docell($obs[$i++]); if(!isset($obs[$i])) break; |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break; |
$pdf->Ln(); |
$this->docell($obs[$i++]); if(!isset($obs[$i])) break; |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break; |
$pdf->Ln(); |
$this->docell($obs[$i++]); if(!isset($obs[$i])) break; |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break; |
/*$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true); |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);*/ |
|
$pdf->selectColumn(1); |
$this->docell($obs[$i++]); if(!isset($obs[$i])) break; |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break; |
$pdf->Ln(); |
$this->docell($obs[$i++]); if(!isset($obs[$i])) break; |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break; |
$pdf->Ln(); |
$this->docell($obs[$i++]); if(!isset($obs[$i])) break; |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break; |
/*$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true); |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true); |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);*/ |
79,122 → 81,224 |
} |
} |
|
// TODO: test plus grand nom d'espèce |
function getlinenb4($txt) { |
// store current object |
$this->pdf->startTransaction(); |
// store starting values |
$start_y = $this->pdf->GetY(); |
$start_page = $this->pdf->getPage(); |
|
$this->pdf->MultiCell($this->column_width, $h=0, $txt, $border=0, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0); |
$end_y = $this->pdf->GetY(); |
$end_page = $this->pdf->getPage(); |
// calculate height |
$height = 0; |
if ($end_page == $start_page) { |
$height = $end_y - $start_y; |
} else { |
for ($page=$start_page; $page <= $end_page; ++$page) { |
$this->setPage($page); |
if ($page == $start_page) { |
// first page |
$height = $this->pdf->h - $start_y - $this->pdf->bMargin; |
} elseif ($page == $end_page) { |
// last page |
$height = $end_y - $this->pdf->tMargin; |
} else { |
$height = $this->pdf->h - $this->pdf->tMargin - $this->bMargin; |
} |
} |
} |
// restore previous object |
$this->pdf = $this->pdf->rollbackTransaction(); |
return $height; |
} |
|
function getlinenb3($txt) { |
return $this->pdf->getStringHeight($this->column_width, $txt); |
} |
|
function getlinenb2($txt) { |
//var_dump($line, $this->pdf->GetStringWidth($line)); |
return ceil($this->pdf->GetStringWidth($txt) / $this->column_width); |
} |
|
function getlinenb($txt) { |
return $this->pdf->getStringHeight('', $txt) / ($this->pdf->getFontSize() * $this->pdf->getCellHeightRatio()); |
} |
|
// singe la propriété CSS3 "text-overflow" : "ellipsis" |
function elude($txt, $limite_lignes = 3) { |
// echo strlen($txt) . ' '. $this->getlinenb($txt) . ' ' . $limite_lignes . "\n"; |
|
$marge = $this->pdf->getCellPaddings()['T'] + $this->pdf->getCellPaddings()['B']; |
$line_height = $this->pdf->getStringHeight($this->column_width, "a") - $marge; |
if($limite_lignes > 1) { |
$lim = $line_height * $limite_lignes + $marge; // $line_height + ($line_height - $marge) * ($limite_lignes - 1); |
} else { |
$lim = $line_height + $marge; |
} |
|
while(strlen($txt) > 4 && ($nb = $this->getlinenb3(strip_tags($txt))) > $lim) { |
//echo "$nb / $line_height: $txt\n"; |
// TODO: mb_internal_encoding() |
$txt = mb_substr($txt, 0, -4, 'UTF-8') . '…'; |
} |
//echo "$txt: $nb / $limite_lignes \n"; |
return $txt; |
} |
|
|
// TODO: affichage pays dans "localité" |
// ORDER BY id_observation |
// intitulé en gras |
// italique pour nom d'espèce, mais pas auteur |
// supprimer les lignes |
function doHTMLcell($obs) { |
$this->pdf->setCellMargins(0,0,0,0); |
$width = $this->column_width = 98; |
|
//echo "cell_padding['T']: " . $this->pdf->getCellPaddings()['T'] . ", cell_padding['B']: " . $this->pdf->getCellPaddings()['B'] . "\n"; |
|
$lh = $this->pdf->getFontSize() * $this->pdf->getCellHeightRatio(); |
//$lh = $this->pdf->GetLineWidth(); |
|
/* |
var_dump($this->pdf->GetLineWidth(), |
$this->pdf->GetCharWidth("a"), |
$this->pdf->getStringHeight(60, "Ê"), |
$this->pdf->getHTMLFontUnits("plop"), |
$this->pdf->GetStringWidth("aa"), |
$lh, |
|
5, |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum..."), |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 5), |
|
4, |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"), |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 4), |
|
3, |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet"), |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 3), |
|
2, |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore"), |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 2), |
|
1, |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur"), |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 1) |
); |
die; |
*/ |
|
|
/* $str = '<strong>Observation</strong> : ' . $obs['commentaire']; |
echo $this->getlinenb(strip_tags($str)) . "\n"; |
echo $this->getlinenb2(strip_tags($str)) . "\n"; |
echo $this->pdf->getStringHeight($width, strip_tags($str)) . "\n"; |
echo $this->pdf->getStringHeight($width, "a") . "\n"; |
echo ( $this->pdf->getStringHeight($width, strip_tags($str)) / $this->pdf->getStringHeight($width, "a")) . "\n"; |
|
die;*/ |
|
// 3ème paramètre = '' equivalent à $this->pdf->getX() |
// 4ème paramètre = '' equivalent à $this->pdf->getY() |
// famille |
$this->pdf->writeHTMLCell($w = $width - 20, '', '', '', |
$html = '<strong>Famille</strong> : ' . $obs['famille'], |
$border = 'LT', $ln = 0, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
|
// N°: TODO: writeHTMLCell() semble bugger |
$this->pdf->Cell($w = 20, '', |
$txt = 'N° : ' . $obs['id_observation'], //. sprintf("%04d", $obs['ordre']) |
$border = 'TR', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
/*$this->pdf->writeHTMLCell($w = 20, '', '', '', |
$html = '<strong>N°</strong> : ' . $obs['id_observation'], //. sprintf("%04d", $obs['ordre']), |
$border = 'TR', $ln = 1, $fill = true, $reset = true, $align = 'R', $autopadding = true);*/ |
|
// espece |
$this->pdf->writeHTMLCell($w = $width, $lh * 2.5, '', '', |
//$html = '<strong>Espèce</strong> : ' . self::elude('Espèce : ', $obs['nom_ret'], 2), |
$html = $this->elude('<strong>Espèce</strong> : ' . $obs['nom_ret'], 2), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// collecteur |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = '<strong>Collecteur</strong> : ' . $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'], |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// localité |
$this->pdf->writeHTMLCell($w = $width, $lh * 3.5, '', '', |
//$html = "<strong>Localité</strong> : " . |
//self::elude('Localité : ', sprintf("%s (%s)\n%s, %s [%s]", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station'], $obs['milieu'] ), 3), |
// $html = self::elude(sprintf("<strong>Localité</strong> : %s (%s)\n%s, %s [%s]", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station'], $obs['milieu']), 3), |
$html = $this->elude(sprintf("<strong>Localité</strong> : %s (%s)", $obs['zone_geo'], $obs['ce_zone_geo']), 2) . "\n" . |
$this->elude(sprintf("%s, %s [%s]", $obs['lieudit'], $obs['station'], $obs['milieu']), 2), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// lon/lat |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = sprintf("<strong>Latitude / Longitude</strong> : %s / %s", $obs['latitude'], $obs['longitude']), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// commentaire |
$this->pdf->writeHTMLCell($w = $width, $lh * 4.5, '', '', |
//$html = '<strong>Observation</strong> : ' . self::elude('Observation : ', $obs['commentaire']), |
$html = self::elude('<strong>Observation</strong> : ' . $obs['commentaire'], 4), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// date |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = '<strong>Date</strong> : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])), |
$border = 'LBR', $ln = 1, $fill = false, $reset = true, $align = 'R', $autopadding = true); |
|
} |
|
function docell($obs) { |
$this->pdf->setCellMargins(0,0,0,0); |
|
$this->pdf->Cell($w = 60, '', |
$txt = 'Famille : ' . $obs['famille'], |
$border = 1, |
$ln = 0, |
$align = 'L', |
$fill = false, |
$link = false, |
$stretch = 1, |
$ignore_min_height = false, |
$calign = 'T', |
$valign = 'M'); |
$border = 'LT', $ln = 0, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
|
$this->pdf->Cell($w = 20, '', |
$txt = 'N° : ' . $obs['id_observation'] /*. sprintf("%04d", $obs['ordre']) */, |
$border = 1, |
$ln = 1, |
$align = 'L', |
$fill = false, |
$link = false, |
$stretch = 1, |
$ignore_min_height = false, |
$calign = 'T', |
$valign = 'M'); |
$border = 'TR', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
|
$this->pdf->Cell($w = 80, '', |
$txt = 'Espèce : ' . $obs['nom_ret'], |
$border = 1, |
$ln = 1, |
$align = 'L', |
$fill = false, |
$link = false, |
$stretch = 1, |
$ignore_min_height = false, |
$calign = 'T', |
$valign = 'M'); |
$border = 'RL', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
|
$this->pdf->Cell($w = 80, '', |
$txt = 'Collecteur : ' . $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'], |
$border = 1, |
$ln = 1, |
$align = 'L', |
$fill = false, |
$link = false, |
$stretch = 1, |
$ignore_min_height = false, |
$calign = 'T', |
$valign = 'M'); |
$border = 'RL', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
|
$this->pdf->MultiCell(80, 20, |
$txt = sprintf("Localité : %s (%s)\n%s, %s", |
$obs['zone_geo'], |
$obs['ce_zone_geo'], |
$obs['lieudit'], |
$obs['station']), |
1, |
'L', |
0, |
1, |
'', |
'', |
true); |
$txt = sprintf("Localité : %s (%s)\n%s, %s", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station']), |
$border = 'RL', 'L', 0, 1, '', '', true); |
|
$this->pdf->Cell($w = 80, '', |
$txt = sprintf("Latitude, Longitude : %s / %s", $obs['latitude'], $obs['longitude']), |
$border = 1, |
$ln = 1, |
$align = 'L', |
$fill = false, |
$link = false, |
$stretch = 1, |
$ignore_min_height = false, |
$calign = 'T', |
$valign = 'M'); |
$border = 'RL', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
|
$this->pdf->MultiCell(80, 20, |
$txt = self::coupeCommentaire("Observation : ", $obs['commentaire']), |
1, |
'L', |
0, |
1, |
'', |
'', |
true); |
$txt = 'Observation : ' . self::elude('Observation : ', $obs['commentaire']), |
$border = 'RL', 'L', 0, 1, '', '', true); |
|
$this->pdf->Cell($w = 80, '', |
$txt = 'Date : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])), |
$border = 1, |
$ln = 1, |
$align = 'R', |
$fill = false, |
$link = false, |
$stretch = 1, |
$ignore_min_height = false, |
$calign = 'T', |
$valign = 'M'); |
$border = 'LBR', $ln = 1, $align = 'R', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
} |
|
|
|
|
|
|
|
function coupeCommentaire($intitule, $commentaire) { |
// singe la propriété CSS3 "text-overflow" : "ellipsis" |
function elude_bis($intitule, $commentaire, $lignes = 3) { |
// TODO: GetLineWidth, GetCharWidth() |
$limite = 3 /* lignes */ * 43 /* caractères */ - strlen($intitule); |
if(mb_strlen($commentaire) < $limite) return 'Observation : ' . $commentaire; |
return 'Observation : ' . mb_substr($commentaire, 0, $limite - 3) . '...'; |
$limite = $lignes /* lignes */ * 43 /* caractères */ - strlen($intitule); |
if(mb_strlen($commentaire) < $limite) return $commentaire; |
return mb_substr($commentaire, 0, $limite - 2) . '…'; |
} |
|
|