PHP使用FPDF添加文本


PHP add text using FPDF

我看到了这个演示http://www.setasign.com/products/fpdi/demos/simple-demo/

<?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();

我想添加try 3文本和不同的坐标(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);

不工作,我很困惑:(

写入(float h,string txt[,混合链接])

此方法从当前位置打印文本。达到右边距时(或遇到字符)出现换行符,文本从左侧继续边缘在方法退出时,当前位置只保留在文本的末尾。可以在文本上添加链接。

参数

h——线路高度。txt-要打印的字符串。link-AddLink()返回的URL或标识符。

正如你所看到的,第一个论点不是立场。你必须先将SetXY放在你想要文本的位置,Write放在那里,SetXY放在另一个位置,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');