略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: PDF_show_xy

2024-11-15

PDF_show_xy

(PHP 4, PECL pdflib >= 1.0.0)

PDF_show_xyOutput text at given position

说明

PDF_show_xy ( resource $p , string $text , float $x , float $y ) : bool

Prints text in the current font. 成功时返回 TRUE, 或者在失败时返回 FALSE

add a note add a note

User Contributed Notes 4 notes

up
0
Christopher Jastram <cej at intech dot com>
13 years ago
Here's a little function that creates a pdf_show_xy_right() function with exactly the same parameters as pdf_show_xy(), except that the third parameter now specifies the right-aligned edge position.

function pdf_show_xy_right(&$pdf, $text, $right, $bottom) {
    $fontname = pdf_get_parameter($pdf, "fontname", 0);
    $font = pdf_findfont($pdf, $fontname, "host", 0);
    $size = pdf_get_value($pdf, "fontsize", 0);
    $width = pdf_stringwidth($pdf, $text, $font, $size);
    pdf_show_xy($pdf, $text, $right-$width, $bottom);
}

Set your font name and size separately, just as you would with pdf_show_xy(), and then call this function like so:

pdf_show_xy_right($pdf, "Hello World", 50, 200);

The third parameter is the right edge, fourth parameter is the baseline.  You do NOT have to pass in the font and size!
up
0
DrPsycho at easynet dot be
16 years ago
No, that's just because in PDF the origin is at the lower left corner
up
0
nid at home dot se
16 years ago
When using PDFLib version 4.0.3 under PHP 4.2.1 on Windows the Y-position is reversed, which means, the Y is the number of pixels that should be visible BELOW the texts baseline.
up
-2
sigve at NwOoSlPfArMaidah dot no
14 years ago
Want to do right-to-left text with pdflib? Just pick the right margin, and send it as $x to this function.

<?php
function pdf_show_xy_backwards ($pdf, $text, $font, $size, $x, $y) {
   
$currx = $x;
    for (
$i = strlen($text); $i > 0; $i--) {
       
$char = substr((string)$text, $i-1, 1);
       
$width = pdf_stringwidth($pdf, (string)$char, $font, $size);
       
$currx = $currx - $width;
       
pdf_show_xy($pdf, (string)$char, $currx, $y);
    }
}
?>

官方地址:https://www.php.net/manual/en/function.pdf-show-xy.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3