TCPDF在本地工作,但不在线

时间:2014-01-24 20:39:18

标签: tcpdf

我正在使用PHP * TCPDF / FPDI类动态生成PDF ..

在本地开发(WAMP / localhost)时......事情一直很好......

现在我已经将内容上传到LIVE服务器..我只得到SAME文件上的空白页面......带有SAME目录结构..

但是,在LIVE环境中进行测试时......它不起作用?

只是一个空白页面,没有错误..等等。

这是我目前使用的代码..

(我试图在构造函数和HTML输出中添加UTF-8编码...... ??

代码:

$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');

每次实时测试时只是一个空白/空白页面。

我错过了什么或做错了什么?

3 个答案:

答案 0 :(得分:0)

固定:

要记住几件事:

1。)在你开始你的OUPUT之前没有任何空格或空格

2。)确保你的FPDI目录中有文件:fpdf_tpl.php ..

(第二个似乎是我最初的垮台):)

答案 1 :(得分:0)

放置TCPDF输出文件时,请确保从服务器的根目录开始。为此,请在输出文件所在的位置运行info.php。打开info.php并几乎一直向下滚动,它将显示您的php文件的完整路径。使用路径有输出位置...

我有这个问题,在我的tcpdf上它解决了问题。

答案 2 :(得分:0)

我也有这个问题。对我来说固定的是添加

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

正好位于$pdf->Output上方。可能与在Bluehost上的WordPress上使用TCPDF有关。