gpt4 book ai didi

php - 尝试使用 FPDF 和 FPDI 写入 PDF 文件

转载 作者:行者123 更新时间:2023-12-02 17:45:26 25 4
gpt4 key购买 nike

我收到了一个 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');

最佳答案

我过去曾使用过一次 FPDF,您说得对,设置 XY 位置非常麻烦。但似乎没有别的办法。

我唯一的建议是考虑

$pdf->SetXY($pdf->GetX() + $x_value, $pdf->GetY() +  $y_value) 

在您不确定应该放置的确切位置的地方。

关于php - 尝试使用 FPDF 和 FPDI 写入 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15417506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com