Question

I am working on dynamically generating a PDF using PHP * the TCPDF/FPDI classes..

While developing locally (WAMP/localhost).. things have been working fine..

now that I have uploaded things to the LIVE server.. I get nothing but a blank page on the SAME files.. with the SAME directory structure..

However, when testing on LIVE environment.. it doesnt work?

Just a blank page, no errors..etc.

here is the code Im currently using..

(I tried to add in the UTF-8 encoding in the constructor AND in the HTML output...??

code:

$live = false;

$targetID = 122;
$targetName = "Name";
$targetClient = "Client Name";

$targetAddress = "address";
$targetCity = "city";
$targetState = "State";
$targetZip = "40202";
$targetPhone = "xxx-555-1212";

$fileCreator = "xxxxx123";  
$fileAuthor = "xxx";
$fileTitle = "Title";
$fileSubject = "Ssubject";

if($live){
$targetLogo = "/path/to/logo/images/targetLogo.jpg";
$sourcePDF = "/path/to/pdf/targetPDF.pdf";
}else{
$targetLogo = "images/targetLogo.jpg";
$sourcePDF = "targetPDF.pdf";
}
$saveAsName = "DYNAMIC_BRANDING.pdf";

//client specific variables
$clientName_color = '#FF0000';
$memberName_color = '#000000';
$clientAddress_color = '#000000';


//------------------[end project vars]---------------------//



// just require TCPDF instead of FPDF
define('FPDF_FONTPATH', 'tcpdf/fonts/');
//include FPDI & TCPDF class library file(s)


if($live){
//ini_set('display_errors', '0');
//error_reporting(E_ALL | E_STRICT);
//live
require('/path/to/tcpdf.php');  
require('/path/to/fpdi.php');  //make sure to include the _TPL file in directory or it throws error.

}else{
ini_set('display_errors', '0');
error_reporting(E_ALL | E_STRICT);
//local file path (WAMP server)
require('tcpdf/tcpdf.php'); //<-- order matters here
require('fpdi/fpdi.php');   //<-- order matters here
}


//Page width in PT: 595.275590551
//Page height in PT: 841.88976378

//Page width in MM (default): 210
//Page height in MMK (default): 297

//$measurementUnits = 'mm'; //[mm or pt] // not needed, used for measurement checking

// initiate FPDI
//http://www.tcpdf.org/doc/code/classTCPDF.html#a134232ae3ad1ec186ed45046f94b7755
//$pdf = new FPDI();
//$pdf = new FPDI('P', 'pt', 'A4');
//$pdf = new FPDI('P', 'mm', 'A4'); //default   
$pdf = new FPDI('P', 'mm', 'A4', true, 'UTF-8', false); //default

//mm to px converter: http://www.endmemo.com/sconvert/millimeterpixel.php
//pt to px converter: http://www.endmemo.com/sconvert/pixelpoint.php
//good for finding values when using image placement (pixel to xxx conversion

$pdf->SetAutoPageBreak(TRUE, 0);  //added to remove HUGE bottom margin

//add project meta data/vars
// set document information
$pdf->SetCreator($fileCreator);
$pdf->SetAuthor($fileAuthor);
$pdf->SetTitle($fileTitle);
$pdf->SetSubject($fileSubject); // displays where?
$pdf->SetKeywords('XXX, XXX, Meeting, 2014, etc'); // meta-tags? meta-data?


// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile($sourcePDF);
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 210mm (width of A4)
$pdf->useTemplate($tplIdx, -1, -1, 210, 297); //-1 to off set shadow test //units:mm
//$pdf->useTemplate($tplIdx, -1, -1,0,0); 


//add 'footer/branding' data at bottom

//position table at bottom
$pdf->SetXY(12, 265);
//set table font
$pdf->SetFont('Arial', "", 9, true);
//$pdf->SetFont('Helvetica', '', 9, true);
//set table color
$pdf->SetTextColor(0, 0, 0); //black

//table html
//add css for easier formatting/styling of overlay content
$html ='<!-- EXAMPLE OF CSS STYLE -->
<style>
#overlay{
    width:523mm;
    padding:0;
    border:0;       
}

.clientName{
    text-align:left;
    color:'.$clientName_color.';
    font-size: 10.5pt;
    font-weight:bold;
    width:223;
}

.clientLogo{
    margin-left:auto;
    margin-right:auto;
    padding:0;
    width:100;
 }

 .memberName{
    text-align:right;
    font-weight:bold;
    width:200;
    color:'.$memberName_color.';
 }

 .clientAddress{
    //font-weight:bold;
    text-align:right;
    width:200;
    color:'.$clientAddress_color.';
 }

 .clientCityState{
    //font-weight:bold;
    text-align:right;
    width:200;
    color:'.$clientAddress_color.';
 }

 .clientPhone{
    //font-weight:bold;
    text-align:right;
    width:200;
    color:'.$clientAddress_color.';
 }
</style>
<table cellspacing="0" cellpadding="0" border="0" width="523">
<tr>
    <td rowspan="6" class="clientName">'.$targetClient.'</td>   
    <td rowspan="6" class="clientLogo"><center><img src="'.$targetLogo.'" height="80" width="90"></center></td>    
    <td class="memberName">'.$targetName.'</td>          
</tr>
<tr>
    <td class="clientAddress">'.$targetAddress.'</td>
</tr>
<tr>
    <td class="clientCityState">'.$targetCity.', '.$targetState.'. '.$targetZip.'</td>      
</tr>
<tr>
    <td class="clientPhone">'.$targetPhone.'</td>      
</tr>
</table>';

//echo($html);
//render out/output the HTML table to pdf overlay (table)
$pdf->writeHTML($html, true, false, true, false, '');

//add page number/count
//position table at bottom
$pdf->SetXY(12, 285);
//set table font
$pdf->SetFont('Helvetica', '', 9);
//set table color
$pdf->SetTextColor(0, 0, 0); //black
$pdf->Write(10, 'Page: '.$pdf->getAliasNumPage().'/'.$pdf->getAliasNbPages(),'', false,'L',true,0, false, false,0,0,'');
//$pdf->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');

//output
$pdf->Output($saveAsName, 'I');

Just a blank/empty WHITE Page each time when testing live..

what am I missing or doing wrong?

Was it helpful?

Solution

fixed:

couple of things to remember:

1.) dont have any blanks or spaces before you start your OUPUT

2.) make sure you have the file: fpdf_tpl.php in your FPDI directory..

(second one seemed to be my downfall at first) :)

OTHER TIPS

I also had this problem. What fixed it for me was adding

while( ob_get_level() ) {
    ob_end_clean();
}

just above $pdf->Output. Might be related to using TCPDF on WordPress with Bluehost.

When you put your TCPDF Output file, Make sure you start from the root of your server. TO do so get a info.php running where your output file is located. Open the info.php and scroll almost all the way down, it will show the full path of your php file. Use the path has for the output location...

I had this issue, on my tcpdf and it solved the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top