簡體   English   中英

嘗試使用FPDF和FPDI寫入PDF文件

[英]Trying to write to a PDF file using FPDF and FPDI

我得到了一個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) 

在您不確定應放置的確切位置的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM