Multi line FPDF footer:

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
breeze351Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
breeze351Author Commented:
Thanks, I couldn't find the answer with google.
1
Ray PaseurCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.