FPDF致命错误

时间:2014-07-09 03:41:10

标签: pdf pdf-generation require fpdf

我正在尝试测试FPDF的实现。下面是我正在测试的代码,但它一直给我错误:“致命错误:在第5行的/home4/fwall/public_html/create-press-release.php中找不到类'FPDF'”。这是我调用下面代码的页面的URL。

我已经确认从正确的位置需要FPDF的php文件,而且它仍在发生。谁能弄明白发生了什么?

require(__DIR__.'/fpdf.php'); //The fpdf folder is in my root directory.

//create a FPDF object
$pdf=new FPDF();

//set document properties
$pdf->SetAuthor('Lana Kovacevic');
$pdf->SetTitle('FPDF tutorial');

//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
$pdf->SetTextColor(50,60,100);

//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');

//insert an image and make it a link
//$pdf->Image('logo.png',10,20,33,0,' ','http://www.fpdf.org/');

//display the title with a border around it
$pdf->SetXY(50,20);
$pdf->SetDrawColor(50,60,100);
$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);

//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->Write(5,'Congratulations! You have generated a PDF.');

//Output the document
$pdf->Output('example1.pdf','I'); 

1 个答案:

答案 0 :(得分:1)

这一行:

require('http://siteurlredacted.com/fpdf/fpdf.php');

可能不会做你期望的事情。该请求将使远程服务器“执行”fpdf.php,返回空白页面,并且您的脚本将包含一个空文件。这就是为什么它没有找到任何要加载的类。

你应该下载FPDF并将文件放在你的文件系统上,在没有HTTP请求的情况下可以访问你的脚本。您可以尝试将fpdf.php放入项目中。

希望这有帮助。