PDF_fit_textline

(PECL pdflib:2.0-2.1.3)

PDF_fit_textline — Place single line of text

Описание

bool PDF_fit_textline ( resource $pdfdoc , string $text , float $x , float $y , string $optlist )

Places a single line of text on the page, subject to various options. Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Коментарии

Here is a function I created in order to allow me to do textblocks on pdflib lite.  Hope this helps someone else, cause all the stuff I've found on php.net has helped me.
$p is your pdf resource 
$text is the string to put in the box
$cols is the number col characters before a carriage return
$xcrd,$ycrd is lower left of first line.

This will accept \n as a newline/carriage return and use it to skip to next line.  It is not setup to hyphenate words, but someday I'll build one, or buy the full pdf package. ;)

function text_block($p,$text,$cols,$xcrd,$ycrd)
{
$font_size=12;  //font size, used to space lines on y axis
$tmplines = explode("\n",$text);
for($j=0;$j<count($tmplines);$j++)
    {
    $tmptxt = explode(" ",$tmplines[$j]);
    $str="";
    for($i=0;$i<count($tmptxt);$i++)
        {
        if($str=="") $str=sprintf("%s",$tmptxt[$i]);
        else    $str=sprintf("%s %s",$str,$tmptxt[$i]);
        if((strlen($str) + strlen($tmptxt[$i+1])) > $cols)
            {
            pdf_fit_textline($p,$str,$xcrd,$ycrd,"");
            $str="";
            $ycrd-=$font_size;
            }
        }
    pdf_fit_textline($p,$str,$xcrd,$ycrd,"");
    $ycrd-=$font_size;
    }
return $ycrd;
}
2006-07-11 20:49:40
http://php5.kiev.ua/manual/ru/function.pdf-fit-textline.html
A patch to the code below to handle an array bounds error that arises:

<?php
$nextText 
"";
if ( ( 
count$tmpTxt ) - ) >= ( $i ) )
$nextText $tmpTxt$i+]; }
               
if ( ( 
strlen$str ) + strlen$nextText ) ) > $cols )
?>
2006-11-27 15:47:13
http://php5.kiev.ua/manual/ru/function.pdf-fit-textline.html
For right now, if you are using PDFlib Lite, you can still use the legacy (depreciated) PDF_show_boxed or $p->show_boxed functions to create a text area. This seems to be a good (if not as full-featured) alternative to the textflow functions, and definitely a whole lot easier than trying to write your own text wrapping/hyphenation solution.
2009-03-24 20:17:02
http://php5.kiev.ua/manual/ru/function.pdf-fit-textline.html
One point about using the PDF_show_boxed function. 

It does not support Unicode. So if you need that support you will need to use this function or the text flow functions.
2009-07-12 18:49:14
http://php5.kiev.ua/manual/ru/function.pdf-fit-textline.html
Автор:
The function PDF_fit_textline has an "optlist" argument which you use to pass options. In other words, PDF_fit_textline contains many functions instead of one. A classical code smell.

The fact that the optlist argument is a string uglyfies this function by a factor of thousand.

Conclusion: when you make functions like PDF_show_boxed deprecated, replace it with a better function instead of doing the opposite.
2011-01-19 02:38:43
http://php5.kiev.ua/manual/ru/function.pdf-fit-textline.html

    Поддержать сайт на родительском проекте КГБ