note 57587 added to ref.pdf
| From: | ragnar at deulos dot com | Date: | Sat, 08 Oct 2005 01:21:36 +0000 |
| Subject: | note 57587 added to ref.pdf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96646@lists.php.net to get a copy of this message | ||
PART I
After one hole day understanding how pdflib works i got the conclusion that its enough hard to draw
just with words to furthermore for drawing a line maybe you will need something like four lines of
code, so i did my own functions to do the life easier and the code more understable to modify and
draw. I also made a function that will draw a rect with the corners round and the posibility even to
fill it ;)
<?php
// pdf_rectangulo(pdf resource, x, y, width, height, corner rounding, stroke width, stroke color,
fill color)
// draws a rect. If u dont want rounded corners set rounding to 0, if u dont want to stroke set the
stroke width to 0 and if u dont want to fill it leave the fill color as an empty string.
function pdf_rectangulo($pdf, $x, $y, $ancho, $alto, $redondeo, $trazado, $c_trazado, $c_relleno) {
if ($redondeo > 0) {
if ($c_relleno != "") {
pdf_color($pdf, "", $c_relleno);
pdf_rect($pdf, ($x + $redondeo), $y, ($ancho - ($redondeo * 2)), $alto);
if (($redondeo * 2) < $alto) {
pdf_rect($pdf, $x, ($y + $redondeo), $redondeo, ($alto - ($redondeo * 2)));
pdf_rect($pdf, ($x + $ancho - $redondeo), ($y + $redondeo), $redondeo, ($alto - ($redondeo *
2)));
}
pdf_fill($pdf);
}
pdf_angulo($pdf, ($x + $redondeo), ($y + $alto - $redondeo), $redondeo, 90, 180, $trazado,
$c_trazado, $c_relleno);
pdf_angulo($pdf, ($x + $ancho - $redondeo), ($y + $alto - $redondeo), $redondeo, 0, 90, $trazado,
$c_trazado, $c_relleno);
pdf_angulo($pdf, ($x + $ancho - $redondeo), ($y + $redondeo), $redondeo, 270, 360, $trazado,
$c_trazado, $c_relleno);
pdf_angulo($pdf, ($x + $redondeo), ($y + $redondeo), $redondeo, 180, 270, $trazado, $c_trazado,
$c_relleno);
pdf_linea($pdf, ($x + $redondeo), ($y + $alto), ($x + $ancho - $redondeo), ($y + $alto), $trazado,
$c_trazado);
pdf_linea($pdf, ($x + $ancho), ($y + $alto - $redondeo), ($x + $ancho), ($y + $redondeo),
$trazado, $c_trazado);
pdf_linea($pdf, ($x + $ancho - $redondeo), $y, ($x + $redondeo), $y, $trazado, $c_trazado);
pdf_linea($pdf, $x, ($y + $redondeo), $x, ($y + $alto - $redondeo), $trazado, $c_trazado);
} else {
if ($trazado == 0) {
pdf_color($pdf, "", $c_relleno);
pdf_rect($pdf, $x, $y, $ancho, $alto);
pdf_fill($pdf);
} elseif ($c_relleno == "") {
pdf_color($pdf, $c_trazado, $c_relleno);
pdf_setlinewidth($pdf, $trazado);
pdf_rect($pdf, $x, $y, $ancho, $alto);
pdf_stroke($pdf);
} else {
pdf_color($pdf, $c_trazado, $c_relleno);
pdf_setlinewidth($pdf, $trazado);
pdf_rect($pdf, $x, $y, $ancho, $alto);
pdf_fill_stroke($pdf);
}
}
}
// pdf_texto(pdf resource, text, x, y, font family, font size, color)
// draws a text of only one line.
function pdf_texto($pdf, $texto, $x, $y, $fuente, $tamaño, $color) {
pdf_color($pdf, "", $color);
pdf_setfont($pdf, $fuente, $tamaño);
pdf_show_xy($pdf, $texto, $x, $y);
}
// pdf_parrafo(pdf resource, text, x, y, width, height, alignment, font family, font size, color)
// writes a paragraph of text.
function pdf_parrafo($pdf, $texto, $x, $y, $ancho, $alto, $alineamiento, $fuente, $tamaño, $color)
{
pdf_setfont($pdf, $fuente, $tamaño);
pdf_color($pdf, "", $color);
pdf_show_boxed($pdf, $texto, $x, $y, $ancho, $alto, $alineamiento, "");
}
// pdf_imagen(pdf resource, image location, x, y, scale)
// add an image to the pdf in the position x, y. if u dont want to make it scale set it as 1 (one).
function pdf_imagen($pdf, $imagen, $x, $y, $escalado) {
$imagen = pdf_open_image_file($pdf, substr($imagen, -3), $imagen, "", 0);
pdf_place_image($pdf, $imagen, $x, $y, $escalado);
pdf_close_image($pdf, $imagen);
}
?>
feel free to make suggestions or whatever u like ;o)
----
Manual Page -- http://www.php.net/manual/en/ref.pdf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57587
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57587&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57587&report=yes
Search -- http://master.php.net/manage/user-notes.php