2014-10-27 37 views
-1

我看到這個演示 http://www.setasign.com/products/fpdi/demos/simple-demo/PHP中使用FPDF

<?php 
require_once('fpdf.php'); 
require_once('fpdi.php'); 

// initiate FPDI 
$pdf = new FPDI(); 
// add a page 
$pdf->AddPage(); 
// set the source file 
$pdf->setSourceFile("PdfDocument.pdf"); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
// use the imported page and place it at point 10,10 with a width of 100 mm 
$pdf->useTemplate($tplIdx, 10, 10, 100); 

// now write some text above the imported page 
$pdf->SetFont('Helvetica'); 
$pdf->SetTextColor(255, 0, 0); 
$pdf->SetXY(30, 30); 
$pdf->Write(0, 'This is just a simple text'); 

$pdf->Output(); 

我要加試3文本和不同coordinat(X,Y)添加文字

我想

$pdf->Write(142.5,170 'This is just a simple text'); 
$pdf->Write(118,175, 'This is just a simple text'); 
$pdf->Write(167.5,175, 'This is just a simple text'); 

和我刪除碼

$pdf->SetXY(30, 30); 

不工作,我很困惑:(

回答

1

寫(浮小時,串TXT [,混合鏈接])

此方法打印從當前位置的文本。當達到右邊距 (或符合\ n字符)時會發生換行並且文字從左邊的 保留下來。在方法退出時,當前位置僅留在文本的末尾。 可以在文字上加上鍊接。

參數

h - 線高。 txt - 要打印的字符串。 鏈接 - 由AddLink()返回的URL或標識符。

正如你所看到的,第一個參數不是一個位置。你必須SetXY起初,你希望你的文字,它WriteSetXY其他位置和Write下一個字符串等位置..

$pdf->SetXY(x1, y1); // position of text1, numerical, of course, not x1 and y1 
$pdf->Write(0, 'Text1'); 
$pdf->SetXY(x2, y2); // position of text2 
$pdf->Write(0, 'Text2'); 
$pdf->SetXY(x3, y3); // position of text3 
$pdf->Write(0, 'Text3'); 
+0

先生,給我舉例 我不明白 – 2014-10-27 04:59:13

+0

謝謝你的兄弟 – 2014-10-27 05:04:53