我收到了一个 PDF 文件,其中包含需要用数据库中的值填写的点。我正在使用 FPDF 库和 FPDI,似乎需要进行大量的试验和错误来定位文本...我必须使用 X 和 Y 坐标才能将文本放置在正确的位置。似乎是一种麻烦且低效的方法。我在这里错过了什么吗?
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
// initiate FPDI
$pdf = new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('1.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 200 mm (This is the image of the included pdf)
$pdf->useTemplate($tplIdx, 10, 10, 200);
// now write some text above the imported page
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',20);
$pdf->SetXY(85, 50);
$pdf->Write(0, "Johnny Walker");
$pdf->SetFont('Arial','B',11);
$pdf->SetXY(92, 69);
$pdf->Write(0, "3");
$pdf->SetFont('Arial','B',10);
$pdf->SetXY(114, 76);
$pdf->Write(0, 'Ventilation Management of the Amyotropic Lateral Scleropsis');
$pdf->SetFont('Arial','B',10);
$pdf->SetXY(114, 90);
$pdf->Write(0, date('m/d/Y'));
$pdf->SetFont('Arial','B',7);
$pdf->SetXY(66, 127);
$pdf->Write(0, '1.5');
$pdf->Output('1.pdf', 'I');
Run Code Online (Sandbox Code Playgroud)
我过去用过FPDF一次,你是对的,设置 XY 位置相当麻烦。但似乎也没有其他办法了。
我唯一建议的是考虑
$pdf->SetXY($pdf->GetX() + $x_value, $pdf->GetY() + $y_value)
Run Code Online (Sandbox Code Playgroud)
在您不确定应该放置的确切位置的地方。
| 归档时间: |
|
| 查看次数: |
8458 次 |
| 最近记录: |