【问题标题】:FPDF Fatal ErrorFPDF 致命错误
【发布时间】:2014-08-29 23:13:50
【问题描述】:

我正在尝试测试 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'); 

【问题讨论】:

    标签: pdf pdf-generation require fpdf


    【解决方案1】:

    这一行:

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

    可能不会达到您的预期。该请求将使远程服务器“执行”fpdf.php,返回一个空白页面,您的脚本将包含一个空文件。这就是它找不到要加载的类的原因。

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

    希望这会有所帮助。

    【讨论】:

    • 谢谢。我假设您的意思是将其称为相对文件?我也试过了,但没有运气。我已经用我现在所拥有的内容更新了这个问题。
    • @Eckstein 在项目内的目录下下载 fpdf 后,我尝试了您的代码。只需将 require 上的绝对路径更改为 require('./fpdf/fpdf.php') 即可
    • 没关系,你是对的。我不需要正确的相对路径。一旦我弄清楚了,它就起作用了。上面的工作解决方案。
    • 太棒了!祝你的项目好运。
    猜你喜欢
    • 1970-01-01
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 2017-01-30
    • 2023-03-17
    • 2023-03-31
    相关资源
    最近更新 更多