New FPDF line height

springthorpeSoftware
springthorpeSoftware used Ask the Experts™
on
Just upgraded from PHP 5.1 to 7.1 so had to also upgrade FPDF to newest version.  Now the FPDF reports have huge line heights. 5 page report is now 19.

No version/upgrade info on the FPDF site, so I'm lost knowing what they may have changed that could cause it.

Any ideas?

Thanks,
Bruce
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:
Bruce, one suggestion might be to refactor and use TCPDF which is more actively maintained than FPDF.  But there may be a shorter path.  Can you set up a simple test that demonstrates the issue?  The less extraneous stuff we have, the better -- just some sample data, and the code that creates the PDF with the too-big lines.  I'll be glad to take a look.

FWIW, I just upgraded all my teaching examples to 1.8.1 and got no differences in line height, so I think we need to see your test cases to understand and fix.

The FPDF web site is not very HTTP and bookmark friendly, but this will help you find the Changelog.
http://www.fpdf.org/en/changelog.php
Thanks, Ray. Will dig into the changelog tomorrow.

Attached are "before" and "after" PDFs.

We use functions to generate the different report sections.  None of our code for the report generator has changed except for the mysql_ to mysqli_ changes needed for the PHP upgrade.  Example code follows.  If you need more advise.

function ReportInfo($rpt='')
{
	global $d, $v, $pdf, $version_id;
	NewSection("Report Information", 120);
	tab();
	$pdf->Cell(75, 10, 'Ordered By:');
	$pdf->Cell(210, 10, $v['ord_rqstr_name']);
	$pdf->Cell(50, 10, 'Phone:');
	$pdf->Cell(0, 10, $v['ord_rqstr_phone'], 0, 1);
	tab();
	$pdf->Cell(75, 10, 'Company:');
	$pdf->Cell(210, 10, $v['ord_rqstr_company']);
	$pdf->Cell(50, 10, 'Email:');
	$pdf->Cell(0, 10, $v['ord_rqstr_email'], 0, 1);
	
	$pdf->Ln(5);
	tab();
	$txt = $v['ord_ship_method'];
	$pdf->Cell(75, 10, 'Delivery Method:');
	$pdf->Cell(0, 10, $txt, 0, 1);
	$pdf->Ln(3);
	if ($txt == "Email") {
		tab();
		$txt = $v['ord_ship_email'];
		if (!$txt > '') $txt = $v['ord_rqstr_email'];
		if ($v['ord_addl_emails'] > '') $txt .= ';' . $v['ord_addl_emails'];
		$pdf->Cell(75, 10, 'Send To:');
		$pdf->MultiCell(0, 9, $txt);
		$pdf->Ln(2);
	} else {
		tab();
		if ($txt == "Office Pickup") $txt = "Hold For:";
		else $txt = "Ship To:";
		$pdf->Cell(75, 10, $txt);
		$myX = $pdf->GetX();
		$pdf->Cell(0, 10, $v['ord_ship_name'], 0, 1);
		$txt = $v['ord_ship_extra'];
		if ($txt > '') { 
			$pdf->SetX($myX);
			$pdf->Cell(0, 10, $txt, 0, 1);
		}
		$txt = $v['ord_ship_addr'];
		if ($txt > '') { 
			$pdf->SetX($myX);
			$pdf->Cell(0, 10, $txt, 0, 1);
		}
		$txt = $v['ord_ship_city'];
		if ($txt > '' && $v['ord_ship_state'] > '') $txt .= ", " . $v['ord_ship_state'];
		$txt = trim($txt .= "  " . $v['ord_ship_zip']);
		if ($txt > '') {
			$pdf->SetX($myX);
			$pdf->Cell(0, 10, $txt, 0, 1);
		}
		$txt = $v['ord_ship_country'];
		if ($txt > '') {
			$pdf->SetX($myX);
			$pdf->Cell(0, 10, $txt, 0, 1);
		}
		$txt = $v['ord_ship_phone'];
		if ($txt > '') {
			tab();
			$pdf->Cell(75, 10, "Phone:");
			$pdf->Cell(0, 10, $txt);
		}
		$txt = $v['ord_ship_email'];
		if ($txt > '') {
			tab();
			$pdf->Cell(75, 10, "Email:");
			$pdf->Cell(0, 10, $txt, 0, 1);
		}
		$txt = $v['ord_ship_tracking'];
		if ($txt > '') {
			tab();
			$pdf->Cell(75, 10, "Tracking #:");
			$pdf->Cell(0, 10, $txt, 0, 1);
		}
	}
	
	if ($rpt != "CAInfo" && $rpt != "Occupancy") {
		$pdf->Ln(5);
		TestNewPage(100);
		tab();
		$tst = $v['ca_name'];
		if (substr($tst, strlen($tst) - 1, 1) == ".") $tst = substr($tst, 0, strlen($tst) - 1);
		$txt = "This report was issued by " . $v['cam_name'] . " on behalf of " . $tst 
			 . ".  Questions regarding its content should be directed to:";
		$pdf->MultiCell(0, 9, $txt);
		$pdf->Ln(2);
		
	// CUSTOM LOGIC FOR CWD GROUP	
		$unfull = '';
		$uemail = '';
		$uphone = '';
	
		if ($v['ord_cam'] == 6 && $_SESSION['sn_user_type'] != "System Admin") {
			$unfull 	= $_SESSION['sn_user_short_name'];
			$uphone 	= $_SESSION['sn_user_phone_pri'];
			$uemail	= $_SESSION['sn_user_email'];
		}
		
		if (strlen($unfull) == 0) {
			$unfull = $v['cam_primary_name'];
			$uphone = $v['cam_primary_phone'];
			$uemail = $v['cam_primary_email'];
		}
		tab();
		$pdf->Cell(0, 10, $unfull, 0, 1, "C");
		tab();
		$pdf->Cell(0, 10, $uphone, 0, 1, "C");
		tab();
		$pdf->Cell(0, 10, $uemail, 0, 1, "C");
	} // end of not CAInfo or Occupancy
	
	$pdf->SetFont('', "I", 4);
	$pdf->Cell(50, 5, "Ver. " . $version_id);
	$txt = $v['ord_id'] . " / " . $v['ca_id'] . " / " . $v['home_id'];
	$pdf->Cell(0, 5, $txt, 0, 1, "R");
	
	tab();
	$pdf->SetFont('Arial', "I", 6);
	$txt = "Created using software provided by Association Data, Inc., (877) 247-2515.";
	$pdf->Cell(0, 10, $txt , 0, 0, "C");

	$pdf->SetFont('', '', 8);
	$_SESSION['sn_section'] = "";
	
}

Open in new window

TST_00069882_01--orig-.pdf
TST_00069882_01--new-.pdf
Most Valuable Expert 2011
Top Expert 2016
Commented:
Thanks for posting that.  

My instincts tell me that this is not a problem with FPDF, or else it would have been identified and called out in the changelog.  The latest version is more than a year old.  And I expect the MySQL queries are bringing back the same data as before.  We do not change the database, only the extension for accessing the database.  It's probably a data-dependent problem, a variable setting or a variable name collision, or something similar.

Unfortunately the code sample is still not concise enough for me to test and show the differences.  I don't have any of your data or the other functions that get called here.  The thing I'm looking for is the SSCCE.  It would be a completely self-contained script that anyone with PHP and FPDF could install and run, with the only difference being the underlying PHP version and the underlying FPDF version.  All of the data and external variables would be mocked in the SSCCE, so there would be no dependencies on external data.

My guess, and it's only a guess, is that the initial settings for the $pdf object are out of whack - perhaps they come from a variable that is different between the two systems.  But the fastest and best way to get to the bottom of this is to get the small, self-contained test case that shows us exactly what is different between the two systems.  In my experience, the process of building the SSCCE will often uncover the issues!
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Resolved.  For that particular report, I was not defining the default orientation, units or paper size.  Was using simply "$pdf = new PDF()" instead of "$pdf = new PDF('P', 'pt', 'Letter').

Thanks the help, though!
Most Valuable Expert 2011
Top Expert 2016

Commented:
... initial settings for the $pdf object are out of whack ...
Bingo!  Glad you got it straightened out :-)

My scan shows these that might need to be checked.

Searching for: $pdf = new
adiBillingGenerator.php(917): $pdf = new PDF("L", "pt", "Letter");
adiReportCAInfo.php(919): $pdf = new PDF();
ajax_report_generator.php(7195): $pdf = new PDF();
Found solution on my own.

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