【问题标题】:PHP add text using FPDFPHP使用FPDF添加文本
【发布时间】:2014-10-27 04:20:11
【问题描述】:

我看到了这个演示 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();

我想添加尝试 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);

不工作,我很困惑:(

【问题讨论】:

    标签: php fpdf


    【解决方案1】:

    Write(float h, string txt [, mixed link])

    此方法从当前位置打印文本。到达右边距时 (或遇到 \n 字符)出现换行符,文本从左侧继续 利润。在方法退出时,当前位置就留在文本的末尾。 可以在文本上放一个链接。

    参数

    h - 行高。 txt - 要打印的字符串。 链接 - 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');
    

    【讨论】:

    • 先生,举个我不明白的例子
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 2014-09-26
    相关资源
    最近更新 更多