Name

draw_one_paragraph -- Paint a paragraph of text to a page

Synopsis

mixed draw_one_paragraph ( int top, int left, int bottom, int right, string text, int pageid[, array parameters] )

Description

This function paints a string of text on a page specified by pageid bounded by the rectangle specified by top, left, bottom, and right. The optional array parameters can be used to override the default text settings when placing the text.

See the documentation on the draw_text() function for details on default settings and the use of the parameters array.

Text is wrapped as needed to keep it within the boundries of the defined box.

If the text string is too large to place in the alloted space, the text that could not be placed is returned. If the entire space is not filled, the value of bottom that would have been exactly filled is returned.

This function does not take into account newlines, and newlines should not be included in text. If you need to place multiple paragraphs seperated by newlines, either use draw_paragraph() or split the text into individual paragraphs before using the function (as in the below example).

Examples

Assuming that $content is a large amount of text, the following lines will turn it into a PDF file, using as many pages as needed:

$pdf = new pdffile;
$p = explode("\n", $content);
$top =720;
$page = $pdf->new_page("letter");
foreach ($p as $one) {
    while (is_string($one)) {
        $one = $pdf->draw_one_paragraph($top, 72, 72, 540, $one, $page);
        if (is_string($one)) {
            $page = $pdf->new_page("letter");
            $top = 720;
        } else {
            $top = $one;
        }
    }
}

See Also

History

This function first appeared in version 1.14.

Bugs

Lines are wrapped at word boundries. If a single word is longer than the alloted space, it is placed on a line by itself.

The behaviour of a text string with a newline is undefined.