PHP Doku:: Gibt Text in der nächsten Zeile aus - function.pdf-continue-text.html

Verlauf / Chronik / History: (3) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzNon-Text MIME-AusgabenPDFPDF FunktionenPDF_continue_text

Ein Service von Reinhard Neidl - Webprogrammierung.

PDF Funktionen

<<PDF_concat

PDF_create_3dview>>

PDF_continue_text

(PHP 4, PECL pdflib >= 1.0.0)

PDF_continue_textGibt Text in der nächsten Zeile aus

Beschreibung

bool PDF_continue_text ( resource $p , string $text )

Schreibt text in die nächste Zeile. Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.


5 BenutzerBeiträge:
- Beiträge aktualisieren...
cbaltaci at turkisp dot com
13.09.2005 12:59
Shortest way to wordwrap in pdf_continue_text. There is no problem with new lines. Thnx to GTECHNICS.com...

<?
$text
= $_POST['texfield']; ;
$lines = explode("\n",$text);
pdf_set_text_pos($pdfdoc,$x ,$y);
foreach(
$lines as $line){
   
$foo = $line;
   
$foo = wordwrap($foo,122,"|");
   
$Arrx = explode("|",$foo);
   
$i = 0;
    while (
$Arrx[$i] != "") {
      
pdf_continue_text($pdfdoc,$Arrx[$i]);
      
$i++;
    }
}
?>
timo dot schmid at gmail dot com
1.07.2005 9:19
I found no possibility to align a Text right. So I wrote a function:

<?php
function pdf_align_right($string, $chars = 10){
   
$string = str_pad($string, $chars, " ", STR_PAD_LEFT);
   
// Spaces in PDF-Documents are only the Half of a Normal Letter: So we replace them with 2 Spaces
   
$string = preg_replace("/ /", "  ", $string);
    return
$string;
}
?>

Note that the 2nd Parameter is NOT the Lenght of the returned String because the Spaces will be replaced with 2 Spaces.
stephen at thelonecoder dot com
28.06.2005 5:06
For wrapping text in pdf this is the method that I have been using .

It handles variable font and sizes and also variable widths on the paragraph.

<?php
        $c
= $db->row['content'];

   
$color = convert_hexcolor_rgbdec($color_hex);
   
pdf_setcolor($pdf, 'both', 'rgb', $color['r'], $color['g'], $color['b']);

   
$font = pdf_findfont($pdf, "$fontStyle", "host", 1);
   
pdf_setfont($pdf, $font, $s);

   
$par1 = stripslashes($c);

   
$j = 0;
   
$n = 0;
    while(
$j < $pw && $c != "") {
          
$f = substr($par1, $n, 1);
          
$fWidth = pdf_stringwidth($pdf, "$f", 1, $s);
          
$j = $j + $fWidth;
          
$fWidth = 0;
          
$n++;
      }
   
$wrap = $n;
   
   
$lead = $s + 2;
   
$paragraph = wordwrap($paragraph, $wrap, "***");
   
$parArr = explode("***", $paragraph);

   
pdf_show_xy($pdf, "$parArr[0]", $x, $y);
   
pdf_set_leading($pdf, $lead);

   
$i = 1;
    while(
$parArr[$i]) {
       
pdf_continue_text($pdf, "$parArr[$i]");
       
$i++;
    }
}
marco at elevate dot nl
6.11.2002 16:09
// Replace the while loop with this foreach and empty lines
// won't be a problem.

foreach($Arr as $line) {
      pdf_continue_text($pdf,$line);
}
npoole at binary dot net
5.07.2002 23:34
This is how I wrap text in a PDF file built from database content...

$foo = mysql_result($results,0,"foo");

$foo = wordwrap($foo,72,"|");

$Arr = explode("|",$foo);
$i = 0;
while ($Arr[$i] != "") {
        pdf_continue_text($pdf,$Arr[$i]);
        $i++;
}

Someone mentioned to me (and rightfully so) that this may be flawed if you have 2 blank lines, and then more text in the variable.  Use it for what you will though, you may find it (or an alteration of it) useful.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)