FPDF 未正确呈现
FPDF is not rendering correctly
我正在使用 FPDF 库在 PHP 中创建一个 PDF,但我无法获得我想要的结果,即我无法将文本写入 PDF 其他所有事情都已正确完成,我已经使用了两种方法
$pdf->SetXY();
$pdf->Write(0,"Some Text");
和
$pdf->Text(10,10, "Some other Text");
这是我的完整代码
<?php
include_once "fpdf/fpdf.php";
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetLineWidth(0.5);
$pdf->Text(10, 10, "Test Data");
$pdf->Line(10, 15, 200, 15);
$pdf->Line(10, 280, 200, 280);
$pdf->Line(10, 15, 10, 280);
$pdf->Line(200, 15, 200, 280);
$pdf->Rect(10, 15, 190, 15);
$pdf->SetXY(30, 30);
$pdf->Write(10, 'Text1');
$pdf->Output();
?>
使用上面的代码我得到以下输出。
你认为我做错了什么?
更新 :-- 正如 Rajdeep Paul 先生所建议的那样,我缺少以下代码行。
$pdf->SetFont("Arial","B","10");
我将它添加到代码中,效果非常好:)
PDF 没有显示任何内容,因为您没有设置字体。像这样设置字体:
$pdf->SetFont("Arial","B","10");
引用如下:
所以你的代码应该是这样的:
<?php
include_once "fpdf/fpdf.php";
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B","10");
$pdf->SetLineWidth(0.5);
$pdf->Text(10, 10, "Test Data");
$pdf->Line(10, 15, 200, 15);
$pdf->Line(10, 280, 200, 280);
$pdf->Line(10, 15, 10, 280);
$pdf->Line(200, 15, 200, 280);
$pdf->Rect(10, 15, 190, 15);
$pdf->SetXY(30, 30);
$pdf->Write(10, 'Text1');
$pdf->Output();
?>
我正在使用 FPDF 库在 PHP 中创建一个 PDF,但我无法获得我想要的结果,即我无法将文本写入 PDF 其他所有事情都已正确完成,我已经使用了两种方法
$pdf->SetXY();
$pdf->Write(0,"Some Text");
和
$pdf->Text(10,10, "Some other Text");
这是我的完整代码
<?php
include_once "fpdf/fpdf.php";
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetLineWidth(0.5);
$pdf->Text(10, 10, "Test Data");
$pdf->Line(10, 15, 200, 15);
$pdf->Line(10, 280, 200, 280);
$pdf->Line(10, 15, 10, 280);
$pdf->Line(200, 15, 200, 280);
$pdf->Rect(10, 15, 190, 15);
$pdf->SetXY(30, 30);
$pdf->Write(10, 'Text1');
$pdf->Output();
?>
使用上面的代码我得到以下输出。
你认为我做错了什么?
更新 :-- 正如 Rajdeep Paul 先生所建议的那样,我缺少以下代码行。
$pdf->SetFont("Arial","B","10");
我将它添加到代码中,效果非常好:)
PDF 没有显示任何内容,因为您没有设置字体。像这样设置字体:
$pdf->SetFont("Arial","B","10");
引用如下:
所以你的代码应该是这样的:
<?php
include_once "fpdf/fpdf.php";
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B","10");
$pdf->SetLineWidth(0.5);
$pdf->Text(10, 10, "Test Data");
$pdf->Line(10, 15, 200, 15);
$pdf->Line(10, 280, 200, 280);
$pdf->Line(10, 15, 10, 280);
$pdf->Line(200, 15, 200, 280);
$pdf->Rect(10, 15, 190, 15);
$pdf->SetXY(30, 30);
$pdf->Write(10, 'Text1');
$pdf->Output();
?>