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 ;)
// pdf_color(pdf resource, stroke color, fill color)
// this is used to set the colors, leave like empty string ("") to dont change the color of what you want. The values are hexadecimal color like in the html (#FF00CC).
function pdf_color($pdf, $trazado, $relleno) {
if ($trazado != "") {
$color = str_replace("#", "", $trazado);
$rojo = (hexdec(substr($color, 0, 2)) / 255);
$verde = (hexdec(substr($color, 2, 2)) / 255);
$azul = (hexdec(substr($color, -2)) / 255);
pdf_setcolor($pdf, "stroke", "rgb", $rojo, $verde, $azul, 0);
}
if ($relleno != "") {
$color = str_replace("#", "", $relleno);
$rojo = (hexdec(substr($color, 0, 2)) / 255);
$verde = (hexdec(substr($color, 2, 2)) / 255);
$azul = (hexdec(substr($color, -2)) / 255);
pdf_setcolor($pdf, "fill", "rgb", $rojo, $verde, $azul, 0);
}
}
// pdf_linea(pdf resource, start x, start y, end x, end y, line width, color of the line)
// draws a line from start to the end with the width and color you want (the color is set in hexadecimal)
function pdf_linea($pdf, $tx, $ty, $bx, $by, $grosor, $color) {
pdf_color($pdf, $color, "");
pdf_setlinewidth($pdf, $grosor);
pdf_moveto($pdf, $tx, $ty);
pdf_lineto($pdf, $bx, $by);
pdf_stroke($pdf);
}
// 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_circulo(pdf resource, x, y, radius, stroke width, stroke color, fill color)
// draws a circle. if u dont want to stroke it set stroke width to 0 and if u dont want to fill it leave the fill color as an empty string.
function pdf_circulo($pdf, $x, $y, $radio, $trazado, $c_trazado, $c_relleno) {
if ($trazado == 0) {
pdf_color($pdf, "", $c_relleno);
pdf_circle($pdf, $x, $y, $radio);
pdf_fill($pdf);
} elseif ($c_relleno == "") {
pdf_color($pdf, $c_trazado, $c_relleno);
pdf_setlinewidth($pdf, $trazado);
pdf_circle($pdf, $x, $y, $radio);
pdf_stroke($pdf);
} else {
pdf_color($pdf, $c_trazado, $c_relleno);
pdf_setlinewidth($pdf, $trazado);
pdf_circle($pdf, $x, $y, $radio);
pdf_fill_stroke($pdf);
}
}
// pdf_angulo(pdf resource, x, y, radius, starting degrees, ending degrees, stroke width, stroke color, fill color)
// draws an arc. if u dont want to stroke it set stroke width to 0 and if u dont want to fill it leave the fill color as an empty string.
function pdf_angulo($pdf, $x, $y, $radio, $angulo1, $angulo2, $trazado, $c_trazado, $c_relleno) {
if ($trazado == 0) {
pdf_color($pdf, "", $c_relleno);
pdf_arcn($pdf, $x, $y, $radio, $angulo1, $angulo2);
pdf_fill($pdf);
pdf_arc($pdf, $x, $y, $radio, $angulo1, $angulo2);
pdf_fill($pdf);
} elseif ($c_relleno == "") {
pdf_color($pdf, $c_trazado, $c_relleno);
pdf_setlinewidth($pdf, $trazado);
pdf_arc($pdf, $x, $y, $radio, $angulo1, $angulo2);
pdf_stroke($pdf);
} else {
pdf_color($pdf, $c_trazado, $c_relleno);
pdf_arcn($pdf, $x, $y, $radio, $angulo1, $angulo2);
pdf_fill($pdf);
pdf_setlinewidth($pdf, $trazado);
pdf_arc($pdf, $x, $y, $radio, $angulo1, $angulo2);
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)