[英]Trying to write to a PDF file using FPDF and FPDI
I was given a PDF file with spots that needed to be filled out with values from the database. 我得到了一个PDF文件,其中包含需要用数据库中的值填充的点。 I'm using FPDF library along with FPDI, and it seems like a lot of trial and error to position your text...I had to play around with the X and Y coordinates to get the text in correct spots.
我正在使用FPDF库以及FPDI,并且看起来很多试验和错误来定位你的文本......我不得不玩X和Y坐标以使文本在正确的位置。 Seems like a cumbersome and inefficient way to do it.
看起来像是一种繁琐而低效的方式。 Am I missing something here ?
我在这里错过了什么吗?
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');
I have used FPDF
in the past once and you're right setting XY positions are quite cumbersome. 我过去曾经使用过
FPDF
,你设置XY位置是非常麻烦的。 But there doesn't seem to be another way. 但似乎没有另一种方式。
The only thing I would suggest is consider 我唯一建议的是考虑
$pdf->SetXY($pdf->GetX() + $x_value, $pdf->GetY() + $y_value)
at places where you aren't sure of the exact position you should place at. 在您不确定应放置的确切位置的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.