面临使用 fpdf 生成 pdf 的问题

发布于 2024-08-14 06:03:34 字数 364 浏览 3 评论 0原文

我收到以下代码的 http500,我不确定出了什么问题。我是 php 新手。我已检查 PDF.php 是否位于正确的目录中,字体也是如此

<?php
define('FPDF_FONTPATH','/home/php/File/PDF/fonts/');
require('/home/php/File/PDF.php');
$pdf=new FPDF('P', 'mm', array(100,150));
$pdf->AddPage();
$pdf->SetFont('times');
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("ruchit.pdf", D);
?>

I am getting http500 for the code below,I am not sure what is wrong. I am new to php. I have checked that PDF.php is in the right directory and so does fonts

<?php
define('FPDF_FONTPATH','/home/php/File/PDF/fonts/');
require('/home/php/File/PDF.php');
$pdf=new FPDF('P', 'mm', array(100,150));
$pdf->AddPage();
$pdf->SetFont('times');
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("ruchit.pdf", D);
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剑心龙吟 2024-08-21 06:03:34

只是为了确定:

  • 您的路径正确吗?
    • /home/php/File/PDF.php 和 /home/php/File/PDF/fonts/ 真的存在吗?
    • 如果我下载并安装最新版本的 fpdf,我有: /.../fpdf16/fpdf.php/.../fpdf16/font/
    • 我没有“文件”目录 - 但我的安装/版本可能与您不同
  • 没有“文件”目录 - 但我在最后一行代码中 ,您应该在 'D' 两边加上引号,以避免出现此通知:注意:使用未定义的常量 D - 假设为“D”

为我的系统设置正确的路径并引用常量/字符串后,“它对我有用”......

所以,问题:您是否有任何错误,例如 Apache 的日志中?

Just to be sure :

  • are your path corrects ?
    • do /home/php/File/PDF.php and /home/php/File/PDF/fonts/ really exist ?
    • If I download and install the last version of fpdf, I have : /.../fpdf16/fpdf.php and /.../fpdf16/font/
    • I have no "File" directory -- but I might not have the same install/version as you
  • on your last line of code, you should put quotes arround the 'D', to avoid this notice : Notice: Use of undefined constant D - assumed 'D'

Just after setting the right pathes for my system, and quoting the constant/string, "it works for me"...

... So, question : do you have any error, in Apache's log for example ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文