Multi line FPDF footer:

breeze351
breeze351 used Ask the Experts™
on
I need to add a multi line footer.  The application is real estate so you have to have a disclaimer at the bottom of the page (It's a legal CYA.  If we screwed up it ain't our fault).  Since different broker's user different statements, I want to make this as easy as possible.  

I'm getting what looks like the "middle" of the variable.  Is there a way to make the entire variable wrap to a new line without having to edit the text and insert breaks?

global $Disclaimer;
$Disclaimer = $_SESSION['Company_Name']." has made every effort to obtained the information regarding these listings from sources deemed reliable. However, we cannot warrant the complete accuracy thereof subject to errors, omissions, change of price, rental or other conditions, prior sale, lease or financing, or withdrawal without notice."; 
require('fpdf.php');
class PDF extends FPDF
{

// Page footer
function Footer()
{
	$Disclaimer = $GLOBALS['Disclaimer'];
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Disclaimer
    $this->Cell(0,10,$Disclaimer,0,0,'C');
}
}

Open in new window


Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
Please see: https://iconoun.com/demo/temp_breeze351.php

The positioning is a little confusing.  To get line breaks inside the "cell" you have to use MultiCell().  The font sizes are given in points, but the document settings are in millimeters, unless otherwise specified.  And there is an OOP design flaw in the Footer() definition.  FPDF should probably have been an abstract class, requiring an extension (everybody extends FPDF) then you could do the right thing with dependency injection in the Footer() definition, instead of having to use global, which is kind of a hack.

I used FPDF 1.8.1 (current) for this demo.  Man page links are in the top comments.
<?php // demo/temp_breeze351.php
/**
 * https://www.experts-exchange.com/questions/29013196/Multi-line-FPDF-footer.html
 *
 * http://www.fpdf.org/en/doc/index.php
 * http://www.fpdf.org/en/doc/footer.htm
 * http://www.fpdf.org/en/doc/sety.htm
 * http://www.fpdf.org/en/doc/setfont.htm
 * http://www.fpdf.org/en/doc/multicell.htm
 * https://www.experts-exchange.com/articles/19999/PHP-Design-Avoiding-Globals-with-Dependency-Injection.html
 */
error_reporting(E_ALL);

// LOAD THE FPDF CLASSES
require_once('fpdf181/fpdf.php');

// EXTEND THE FPDF CLASS
class PDF extends FPDF
{
    public function Footer()
    {
        // OOP DESIGN FAIL - FOOTER HAS NO PARAMETERS
        global $disclaimer;

        $this->SetY(-15);
        $this->SetFont
        ( 'Arial'  // FONT NAME
        , 'I'      // ITALIC
        , 8        // 8-POINT
        )
        ;
        $this->Multicell
        ( 0             // WIDTH EXTENDS TO RIGHT MARGIN
        , 3             // CELL HEIGHT IN MILLIMETERS
        , $disclaimer   // TEXT
        , 0             // NO BORDER
        , 'L'           // ALIGNMENT
        )
        ;
    }
}


// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= 'storage'
. DIRECTORY_SEPARATOR
. 'temp_breeze351'
. '.pdf'
;
$pdf_file_name
= getcwd()
. DIRECTORY_SEPARATOR
. $pdf_file_link
;


// SIMULATED SESSION
$_SESSION['Company_Name'] = 'McLean Real Estate';
$disclaimer = $_SESSION['Company_Name']." has made every effort to obtained the information regarding these listings from sources deemed reliable. However, we cannot warrant the complete accuracy thereof subject to errors, omissions, change of price, rental or other conditions, prior sale, lease or financing, or withdrawal without notice.";



// SOME VARIABLES FOR OUR TESTS (COULD COME FROM DATA BASE, ETC)
$text = 'Hello World!';

// DO THE HELLO WORLD EXERCISE IN WHITE ON A BLUE BACKGROUND
$pdf = new PDF('P', 'mm', 'Letter');
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->SetFillColor(   0,    0, 0xFF);
$pdf->SetTextColor(0xFF, 0xFF, 0xFF);
$pdf->Cell(40, 10, $text, 0, 2, 'L', TRUE);

// RESET TEXT COLOR TO GRAY
$pdf->SetTextColor(0x80, 0x80, 0x80);

// OUTPUT IMPLIES CLOSE(); CLOSE IMPLIES FOOTER()
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">See the PDF</a>';

Open in new window

Author

Commented:
Thanks, I couldn't find the answer with google.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Just so happens that I've been tinkering with FPDF a lot lately, or I would have been googling, too!  Thanks for the points and thanks for using E-E, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial