Fix: Line at bottom of PDF was too long

This commit is contained in:
Laurent Destailleur 2012-10-21 16:11:46 +02:00
parent 8fe8a1a6fd
commit df4bfc77a4

View File

@ -517,203 +517,211 @@ function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default
} }
/** /**
* Show footer of page for PDF generation * Show footer of page for PDF generation
* *
* @param PDF &$pdf The PDF factory * @param PDF &$pdf The PDF factory
* @param Translate $outputlangs Object lang for output * @param Translate $outputlangs Object lang for output
* @param string $paramfreetext Constant name of free text * @param string $paramfreetext Constant name of free text
* @param Societe $fromcompany Object company * @param Societe $fromcompany Object company
* @param int $marge_basse Margin bottom * @param int $marge_basse Margin bottom we use for the autobreak
* @param int $marge_gauche Margin left * @param int $marge_gauche Margin left (no more used)
* @param int $page_hauteur Page height * @param int $page_hauteur Page height (no more used)
* @param Object $object Object shown in PDF * @param Object $object Object shown in PDF
* @param int $showdetails Show company details * @param int $showdetails Show company details into footer. This param seems to not be used by standard version.
* @return void * @return int Return height of bottom margin including footer text
*/ */
function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0) function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0)
{ {
global $conf,$user; global $conf,$user;
$outputlangs->load("dict"); $outputlangs->load("dict");
$line=''; $line='';
// Line of free text $dims=$pdf->getPageDimensions();
if (! empty($conf->global->$paramfreetext))
{ // Line of free text
// Make substitution if (! empty($conf->global->$paramfreetext))
$substitutionarray=array( {
'__FROM_NAME__' => $fromcompany->nom, // Make substitution
'__FROM_EMAIL__' => $fromcompany->email, $substitutionarray=array(
'__TOTAL_TTC__' => $object->total_ttc, '__FROM_NAME__' => $fromcompany->nom,
'__TOTAL_HT__' => $object->total_ht, '__FROM_EMAIL__' => $fromcompany->email,
'__TOTAL_VAT__' => $object->total_vat '__TOTAL_TTC__' => $object->total_ttc,
); '__TOTAL_HT__' => $object->total_ht,
complete_substitutions_array($substitutionarray,$outputlangs,$object); '__TOTAL_VAT__' => $object->total_vat
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); );
$line.=$outputlangs->convToOutputCharset($newfreetext); complete_substitutions_array($substitutionarray,$outputlangs,$object);
} $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
$line.=$outputlangs->convToOutputCharset($newfreetext);
// First line of company infos }
if ($showdetails) // First line of company infos
{
$line1=""; if ($showdetails)
// Company name {
if ($fromcompany->name) $line1="";
{ // Company name
$line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name; if ($fromcompany->name)
} {
// Address $line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
if ($fromcompany->address) }
{ // Address
$line1.=($line1?" - ":"").$fromcompany->address; if ($fromcompany->address)
} {
// Zip code $line1.=($line1?" - ":"").$fromcompany->address;
if ($fromcompany->zip) }
{ // Zip code
$line1.=($line1?" - ":"").$fromcompany->zip; if ($fromcompany->zip)
} {
// Town $line1.=($line1?" - ":"").$fromcompany->zip;
if ($fromcompany->town) }
{ // Town
$line1.=($line1?" ":"").$fromcompany->town; if ($fromcompany->town)
} {
// Phone $line1.=($line1?" ":"").$fromcompany->town;
if ($fromcompany->phone) }
{ // Phone
$line1.=($line1?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone; if ($fromcompany->phone)
} {
// Fax $line1.=($line1?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
if ($fromcompany->fax) }
{ // Fax
$line1.=($line1?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax; if ($fromcompany->fax)
} {
$line1.=($line1?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
$line2=""; }
// URL
if ($fromcompany->url) $line2="";
{ // URL
$line2.=($line2?" - ":"").$fromcompany->url; if ($fromcompany->url)
} {
// Email $line2.=($line2?" - ":"").$fromcompany->url;
if ($fromcompany->email) }
{ // Email
$line2.=($line2?" - ":"").$fromcompany->email; if ($fromcompany->email)
} {
} $line2.=($line2?" - ":"").$fromcompany->email;
}
// Line 3 of company infos }
$line3="";
// Juridical status // Line 3 of company infos
if ($fromcompany->forme_juridique_code) $line3="";
{ // Juridical status
$line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code)); if ($fromcompany->forme_juridique_code)
} {
// Capital $line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
if ($fromcompany->capital) }
{ // Capital
$line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->currency); if ($fromcompany->capital)
} {
// Prof Id 1 $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->currency);
if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2)) }
{ // Prof Id 1
$field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code); if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; {
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1); $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code);
} if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
// Prof Id 2 $line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
if ($fromcompany->idprof2) }
{ // Prof Id 2
$field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code); if ($fromcompany->idprof2)
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; {
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2); $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code);
} if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
// Line 4 of company infos }
$line4="";
// Prof Id 3 // Line 4 of company infos
if ($fromcompany->idprof3) $line4="";
{ // Prof Id 3
$field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code); if ($fromcompany->idprof3)
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; {
$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3); $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code);
} if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
// Prof Id 4 $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
if ($fromcompany->idprof4) }
{ // Prof Id 4
$field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code); if ($fromcompany->idprof4)
if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; {
$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4); $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code);
} if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
// IntraCommunautary VAT $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
if ($fromcompany->tva_intra != '') }
{ // IntraCommunautary VAT
$line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra); if ($fromcompany->tva_intra != '')
} {
$line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
$pdf->SetFont('','',7); }
$pdf->SetDrawColor(224,224,224);
$pdf->SetFont('','',7);
// On positionne le debut du bas de page selon nbre de lignes de ce bas de page $pdf->SetDrawColor(224,224,224);
$nbofline=dol_nboflines_bis($line,0,$outputlangs->charset_output);
//print 'nbofline='.$nbofline; exit; // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
//print 'e'.$line.'t'.dol_nboflines($line);exit; $nbofline=dol_nboflines_bis($line,0,$outputlangs->charset_output);
$posy=$marge_basse + ($nbofline*3) + ($line1?3:0) + ($line2?3:0) + ($line3?3:0) + ($line4?3:0); //print 'nbofline='.$nbofline; exit;
//print 'e'.$line.'t'.dol_nboflines($line);exit;
if ($line) // Free text $marginwithfooter=$marge_basse + ($nbofline*3) + (! empty($line1)?3:0) + (! empty($line2)?3:0) + (! empty($line3)?3:0) + (! empty($line4)?3:0);
{ $posy=$marginwithfooter+0;
$pdf->SetXY($marge_gauche,-$posy);
$width=20000; $align='L'; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text. if ($line) // Free text
if ($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT) { $width=200; $align='C'; } {
$pdf->MultiCell($width, 3, $line, 0, $align, 0); $pdf->SetXY($dims['lm'],-$posy);
$posy-=($nbofline*3); // 6 of ligne + 3 of MultiCell $width=20000; $align='L'; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
} if (! empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
$width=200; $align='C';
$pdf->SetY(-$posy); }
$pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy); $pdf->MultiCell($width, 3, $line, 0, $align, 0);
$posy--; $posy-=($nbofline*3); // 6 of ligne + 3 of MultiCell
}
if ($line1)
{ $pdf->SetY(-$posy);
$pdf->SetFont('','B',7); $pdf->line($dims['lm'], $dims['hk']-$posy, $dims['wk']-$dims['rm'], $dims['hk']-$posy);
$pdf->SetXY($marge_gauche,-$posy); $posy--;
$pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
$posy-=3; if (! empty($line1))
$pdf->SetFont('','',7); {
} $pdf->SetFont('','B',7);
$pdf->SetXY($dims['lm'],-$posy);
if ($line2) $pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
{ $posy-=3;
$pdf->SetFont('','B',7); $pdf->SetFont('','',7);
$pdf->SetXY($marge_gauche,-$posy); }
$pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
$posy-=3; if (! empty($line2))
$pdf->SetFont('','',7); {
} $pdf->SetFont('','B',7);
$pdf->SetXY($dims['lm'],-$posy);
if ($line3) $pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
{ $posy-=3;
$pdf->SetXY($marge_gauche,-$posy); $pdf->SetFont('','',7);
$pdf->MultiCell(200, 2, $line3, 0, 'C', 0); }
}
if (! empty($line3))
if ($line4) {
{ $pdf->SetXY($dims['lm'],-$posy);
$posy-=3; $pdf->MultiCell(200, 2, $line3, 0, 'C', 0);
$pdf->SetXY($marge_gauche,-$posy); }
$pdf->MultiCell(200, 2, $line4, 0, 'C', 0);
} if (! empty($line4))
{
// Show page nb only on iso languages (so default Helvetica font) $posy-=3;
if (pdf_getPDFFont($outputlangs) == 'Helvetica') $pdf->SetXY($dims['lm'],-$posy);
{ $pdf->MultiCell(200, 2, $line4, 0, 'C', 0);
$pdf->SetXY(-20,-$posy); }
$pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
//print 'xxx'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit; // Show page nb only on iso languages (so default Helvetica font)
} if (pdf_getPDFFont($outputlangs) == 'Helvetica')
{
$pdf->SetXY(-20,-$posy);
$pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
//print 'xxx'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
}
return $marginwithfooter;
} }
/** /**
* Show linked objects for PDF generation * Show linked objects for PDF generation
* *