Horde_Pdf_Writer::text PHP Method

text() public method

The origin is on the left of the first character, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use {@link cell()}, {@link multiCell()} or {@link write()} which are the standard methods to print text. All coordinates can be negative to provide values from the right or bottom edge of the page (since File_Pdf 0.2.0, Horde 3.2).
See also: setFont()
See also: cell()
See also: multiCell()
See also: write()
public text ( float $x, float $y, string $text )
$x float Abscissa of the origin.
$y float Ordinate of the origin.
$text string String to print.
    public function text($x, $y, $text)
    {
        if ($x < 0) {
            $x += $this->w;
        }
        if ($y < 0) {
            $y += $this->h;
        }
        /* Scale coordinates into points and set correct Y position. */
        $x = $this->_toPt($x);
        $y = $this->hPt - $this->_toPt($y);
        /* Escape any potentially harmful characters. */
        $text = $this->_escape($text);
        $out = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x, $y, $text);
        if ($this->_underline && $text != '') {
            $out .= ' ' . $this->_doUnderline($x, $y, $text);
        }
        if ($this->_color_flag) {
            $out = sprintf('q %s %s Q', $this->_text_color, $out);
        }
        $this->_out($out);
    }

Usage Example

コード例 #1
0
ファイル: WriterTest.php プロジェクト: jubinpatel/horde
 public function testHelloWorldCompressed()
 {
     $pdf = new Horde_Pdf_Writer(array('orientation' => 'P', 'format' => 'A4'));
     $pdf->setInfo('CreationDate', $this->fixtureCreationDate());
     $pdf->open();
     $pdf->setCompression(false);
     $pdf->addPage();
     $pdf->setFont('Courier', '', 8);
     $pdf->text(100, 100, 'First page');
     $pdf->setFontSize(20);
     $pdf->text(100, 200, 'HELLO WORLD!');
     $pdf->addPage();
     $pdf->setFont('Arial', 'BI', 12);
     $pdf->text(100, 100, 'Second page');
     $actual = $pdf->getOutput();
     $expected = $this->fixture('hello_world_compressed');
     $this->assertEquals($expected, $actual);
 }