Example #1
0
 function drawText($text, $left, $right, $height, $style)
 {
     $h = $height;
     // Creating duplicate (temp)
     $this->_convertPosition($left, $height);
     $this->_convertPosition($right, $h);
     pdf_setcolor($this->pdf, 'fill', $style['fill'][0], $style['fill'][1], $style['fill'][2], $style['fill'][3], $style['fill'][4]);
     pdf_setfont($this->pdf, $this->font, $style['font']);
     pdf_show_boxed($this->pdf, $text, $left, $height - $style['font'], $right - $left, $style['font'], $style['align'], '');
 }
 function setrgbcolor($r, $g, $b)
 {
     pdf_setcolor($this->pdf, "both", "rgb", $r, $g, $b, 0);
 }
Example #3
0
 /**
  * Set the PDF fill style
  *
  * @param mixed $fillStyle The fillstyle to return, false if the one
  *   explicitly set
  * @return bool True if set (so that a line should be drawn)
  * @access private
  */
 function _setFillStyle($fillStyle = false)
 {
     if ($fillStyle === false) {
         $fillStyle = $this->_fillStyle;
     }
     if ($fillStyle == 'transparent' || $fillStyle === false) {
         return false;
     }
     $color = $this->_color($fillStyle);
     if ($this->_pdflib < 4) {
         pdf_setrgbcolor_fill($this->_pdf, $color[0] / 255, $color[1] / 255, $color[2] / 255);
     } else {
         pdf_setcolor($this->_pdf, 'fill', 'rgb', $color[0], $color[1], $color[2], 0);
     }
     return true;
 }
Example #4
0
 function _bullet(&$bullet)
 {
     $type = '';
     $this->pdf_cy = pdf_get_value($this->pdf, "texty", null);
     pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi');
     $height = 10;
     $txt = strip_markups($bullet->text);
     pdf_save($this->pdf);
     pdf_translate($this->pdf, 0, $this->pdf_y);
     pdf_scale($this->pdf, 1, -1);
     pdf_set_font($this->pdf, $this->pdf_font, 12, 'winansi');
     $leading = pdf_get_value($this->pdf, "leading", null);
     $inc = $leading;
     while (pdf_show_boxed($this->pdf, $txt, $this->pdf_cx + 30, $this->pdf_y - $this->pdf_cy, $this->pdf_x - 2 * ($this->pdf_cx + 20), $height, 'left', 'blind')) {
         $height += $inc;
     }
     pdf_restore($this->pdf);
     //clean up eols so we get a nice pdf output
     if (strstr($txt, "\r\n")) {
         $eol = "\r\n";
     } elseif (strstr($txt, "\r")) {
         $eol = "\r";
     } else {
         $eol = "\n";
     }
     $txt = str_replace($eol, " ", $txt);
     $txt = str_replace("  ", " ", $txt);
     if ($this->pdf_cy + $height > $this->pdf_y - 40) {
         $this->my_pdf_page_number($this->pdf, $this->pdf_x, $this->pdf_y);
         $this->my_new_pdf_end_page($this->pdf);
         $this->my_new_pdf_page($this->pdf, $this->pdf_x, $this->pdf_y, true);
         $this->pdf_cx = 40;
         $this->pdf_cy = 60;
     }
     pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi');
     if ($bullet->type == 'speaker') {
         pdf_setcolor($this->pdf, 'fill', 'rgb', 1, 0, 0, null);
     }
     if (!empty($bullet->start)) {
         if (is_numeric($bullet->start)) {
             $this->objs[$this->coid]->num = (int) $bullet->start;
         } else {
             $this->objs[$this->coid]->alpha = $bullet->start;
         }
     }
     if (!empty($bullet->type)) {
         $type = $bullet->type;
     } else {
         if (!empty($this->objs[$this->coid]->type)) {
             $type = $this->objs[$this->coid]->type;
         }
     }
     switch ($type) {
         case 'numbered':
         case 'number':
         case 'decimal':
             $symbol = ++$this->objs[$this->coid]->num . '.';
             $pdf_cx_height = 30;
             break;
         case 'no-bullet':
         case 'none':
             $symbol = '';
             $pdf_cx_height = 20;
             break;
         case 'alpha':
             $symbol = $this->objs[$this->coid]->alpha++ . '.';
             break;
         case 'ALPHA':
             $symbol = strtoupper($this->objs[$this->coid]->alpha++) . '.';
             $pdf_cx_height = 30;
             break;
         case 'asterisk':
             $symbol = '*';
             $pdf_cx_height = 20;
             break;
         case 'hyphen':
             $symbol = '-';
             $pdf_cx_height = 20;
             break;
         default:
             $symbol = 'o';
             $pdf_cx_height = 20;
             break;
     }
     pdf_show_xy($this->pdf, $symbol, $this->pdf_cx + 20 + $bullet->level * 10, $this->pdf_cy + $leading - 1);
     pdf_show_boxed($this->pdf, $txt, $this->pdf_cx + 40 + $bullet->level * 10, $this->pdf_cy - $height, $this->pdf_x - 2 * ($this->pdf_cx + 20), $height, 'left', null);
     pdf_continue_text($this->pdf, "\n");
     $this->pdf_cy = pdf_get_value($this->pdf, "texty", null);
     pdf_set_text_pos($this->pdf, $this->pdf_cx, $this->pdf_cy - $leading / 2);
     pdf_setcolor($this->pdf, 'fill', 'rgb', 0, 0, 0, null);
 }
Example #5
0
pdf_show_xy($pdf, "* F A C T U R A *", $x - 250, $y - 112);
pdf_setcolor($pdf, 'fill', 'gray', 0.9, 0, 0, 0);
pdf_rect($pdf, 20, 80, $x - 40, $y - 212);
pdf_fill_stroke($pdf);
$offset = 184;
$i = 0;
while ($y - $offset > 80) {
    pdf_setcolor($pdf, 'fill', 'gray', $i % 2 ? 0.8 : 1, 0, 0, 0);
    pdf_setcolor($pdf, 'stroke', 'gray', $i % 2 ? 0.8 : 1, 0, 0, 0);
    pdf_rect($pdf, 21, $y - $offset, $x - 42, 24);
    pdf_fill_stroke($pdf);
    $i++;
    $offset += 24;
}
pdf_setcolor($pdf, 'fill', 'gray', 0, 0, 0, 0);
pdf_setcolor($pdf, 'stroke', 'gray', 0, 0, 0, 0);
pdf_moveto($pdf, 20, $y - 160);
pdf_lineto($pdf, $x - 20, $y - 160);
pdf_stroke($pdf);
pdf_moveto($pdf, $x - 140, $y - 160);
pdf_lineto($pdf, $x - 140, 80);
pdf_stroke($pdf);
pdf_set_font($pdf, "Times-Bold", 18, winansi);
pdf_show_xy($pdf, "Articulo", 30, $y - 150);
pdf_show_xy($pdf, "Precio", $x - 100, $y - 150);
pdf_set_font($pdf, "Times-Italic", 15, winansi);
$offset = 177;
foreach ($items as $item) {
    pdf_show_xy($pdf, $item[0], 30, $y - $offset);
    pdf_show_boxed($pdf, '$' . number_format($item[1], 2), $x - 55, $y - $offset, 0, 0, 'right');
    $offset += 24;
Example #6
0
$w = 40;
// the data and color for each column
$data = array('120', '160', '300', '240');
$color = array('#4EC3BC', '#DAA876', '#E29CC8', '#FDE0C6');
// get into some meat now, cheese for vegetarians;
for ($i = 0; $i < count($data); $i++) {
    // calculate the height of the bar
    $y_ht = $data[$i] / max($data) * 100;
    // set the color for each bar
    list($r, $g, $b) = hex2rgb($color[$i]);
    pdf_setcolor($pdf, "fill", "rgb", $r, $g, $b, 0);
    // draw the bar
    pdf_rect($pdf, $x, $y, $w, $y_ht);
    pdf_fill_stroke($pdf);
    // write the bar label
    pdf_setcolor($pdf, "fill", "rgb", 0, 0, 0, 0);
    pdf_setfont($pdf, $font, 10);
    pdf_show_xy($pdf, $data[$i], $x + 12, $y - 16);
    // go to the next bar
    $x = $x + $w + 40;
}
// done
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
// send it to browser
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=pdf_example3.pdf");
readfile($filename);
unlink($filename);
// function to convert a standard rgb from hex to float
Example #7
0
 function add_poll($name, $opts, $ttl_votes)
 {
     $this->y = pdf_get_value($this->pdf, 'texty', 0) - 3;
     pdf_set_text_pos($this->pdf, $this->wmargin, $this->y - 3);
     pdf_setfont($this->pdf, $this->fonts['Courier-Bold'], 20);
     pdf_continue_text($this->pdf, $name);
     pdf_setfont($this->pdf, $this->fonts['Courier-Bold'], 16);
     pdf_show($this->pdf, '(total votes: ' . $ttl_votes . ')');
     $this->draw_line();
     $ttl_w = round($this->pw * 0.66);
     $ttl_h = 20;
     $p1 = floor($ttl_w / 100);
     $this->y -= 10;
     /* avoid /0 warnings and safe to do, since we'd be multiplying 0 since there are no votes */
     if (!$ttl_votes) {
         $ttl_votes = 1;
     }
     pdf_setfont($this->pdf, $this->fonts['Helvetica-Bold'], 14);
     foreach ($opts as $o) {
         $w1 = $p1 * ($o['votes'] / $ttl_votes * 100);
         $h1 = $this->y - $ttl_h;
         pdf_setcolor($this->pdf, 'both', 'rgb', 0.92, 0.92, 0.92);
         pdf_rect($this->pdf, $this->wmargin, $h1, $w1, $ttl_h);
         pdf_fill_stroke($this->pdf);
         pdf_setcolor($this->pdf, 'both', 'rgb', 0, 0, 0);
         pdf_show_xy($this->pdf, $o['name'] . "\t\t" . $o['votes'] . '/(' . round($o['votes'] / $ttl_votes * 100) . '%)', $this->wmargin + 2, $h1 + 3);
         $this->y = $h1 - 10;
     }
 }
 pdf_moveto($pdf, 660, 150);
 pdf_lineto($pdf, 680, 49);
 pdf_lineto($pdf, 695, 69);
 pdf_lineto($pdf, 716, 55);
 pdf_lineto($pdf, 696, 150);
 pdf_closepath($pdf);
 pdf_fill($pdf);
 // outline ribbon 2
 pdf_moveto($pdf, 660, 150);
 pdf_lineto($pdf, 680, 49);
 pdf_lineto($pdf, 695, 69);
 pdf_lineto($pdf, 716, 55);
 pdf_lineto($pdf, 696, 150);
 pdf_closepath($pdf);
 pdf_stroke($pdf);
 pdf_setcolor($pdf, 'fill', 'rgb', 1, 0, 0, 0);
 // red
 //draw rosette
 draw_star(665, 175, 32, 57, 10, $pdf, true);
 //outline rosette
 draw_star(665, 175, 32, 57, 10, $pdf, false);
 // finish up the page and prepare to output
 pdf_end_page($pdf);
 pdf_close($pdf);
 $data = pdf_get_buffer($pdf);
 // generate the headers to help a browser choose the correct application
 header('Content-type: application/pdf');
 header('Content-disposition: inline; filename=test.pdf');
 header('Content-length: ' . strlen($data));
 // output PDF
 echo $data;