Beispiel #1
0
 function drawPie($centerX, $centerY, $radius, $begin, $end, $style)
 {
     $this->_convertPosition($centerX, $centerY);
     $radius = $radius * min($this->width, $this->height);
     pdf_setcolor($this->pdf, 'stroke', $style['line'][0], $style['line'][1], $style['line'][2], $style['line'][3], $style['line'][4]);
     if (isset($style['fill'])) {
         pdf_setcolor($this->pdf, 'fill', $style['fill'][0], $style['fill'][1], $style['fill'][2], $style['fill'][3], $style['fill'][4]);
     }
     pdf_setlinewidth($this->pdf, $style['line-width']);
     pdf_moveto($this->pdf, $centerX, $centerY);
     pdf_arc($this->pdf, $centerX, $centerY, $radius, $begin, $end);
     pdf_lineto($this->pdf, $centerX, $centerY);
     if (isset($style['fill'])) {
         pdf_closepath_fill_stroke($this->pdf);
     } else {
         pdf_closepath_stroke($this->pdf);
     }
 }
 function moveto($x, $y)
 {
     pdf_moveto($this->pdf, $x, $y);
 }
Beispiel #3
0
 /**
  * Draw an ellipse
  *
  * Parameter array:
  * 'x': int X center point
  * 'y': int Y center point
  * 'rx': int X radius
  * 'ry': int Y radius
  * 'fill': mixed [optional] The fill color
  * 'line': mixed [optional] The line color
  * @param array $params Parameter array
  */
 function ellipse($params)
 {
     $x = $this->_getX($params['x']);
     $y = $this->_getY($params['y']);
     $rx = $this->_getX($params['rx']);
     $ry = $this->_getY($params['ry']);
     $fillColor = isset($params['fill']) ? $params['line'] : false;
     $lineColor = isset($params['line']) ? $params['line'] : false;
     $line = $this->_setLineStyle($lineColor);
     $fill = $this->_setFillStyle($fillColor);
     if ($line || $fill) {
         if ($rx == $ry) {
             pdf_circle($this->_pdf, $this->_getX($x), $this->_getY($y), $rx);
         } else {
             pdf_moveto($this->_pdf, $this->_getX($x - $rx), $this->_getY($y));
             pdf_curveto($this->_pdf, $this->_getX($x - $rx), $this->_getY($y), $this->_getX($x - $rx), $this->_getY($y - $ry), $this->_getX($x), $this->_getY($y - $ry));
             pdf_curveto($this->_pdf, $this->_getX($x), $this->_getY($y - $ry), $this->_getX($x + $rx), $this->_getY($y - $ry), $this->_getX($x + $rx), $this->_getY($y));
             pdf_curveto($this->_pdf, $this->_getX($x + $rx), $this->_getY($y), $this->_getX($x + $rx), $this->_getY($y + $ry), $this->_getX($x), $this->_getY($y + $ry));
             pdf_curveto($this->_pdf, $this->_getX($x), $this->_getY($y + $ry), $this->_getX($x - $rx), $this->_getY($y + $ry), $this->_getX($x - $rx), $this->_getY($y));
         }
         if ($line && $fill) {
             pdf_fill_stroke($this->_pdf);
         } elseif ($line) {
             pdf_stroke($this->_pdf);
         } elseif ($fill) {
             pdf_fill($this->_pdf);
         }
     }
     parent::ellipse($params);
 }
<?php

$p = PDF_new();
PDF_open_file($p);
$im = pdf_open_jpeg($p, "php-big.jpg");
$template = pdf_begin_template($p, 595, 842);
pdf_save($p);
pdf_place_image($p, $im, 4, 803, 0.25);
pdf_place_image($p, $im, 525, 803, 0.25);
pdf_moveto($p, 0, 795);
pdf_lineto($p, 595, 795);
pdf_stroke($p);
$font = PDF_findfont($p, "Times-Bold", "host", 0);
PDF_setfont($p, $font, 38.0);
pdf_show_xy($p, "PDF Template Example", 100, 807);
pdf_restore($p);
pdf_end_template($p);
pdf_close_image($p, $im);
PDF_begin_page($p, 595, 842);
pdf_place_image($p, $template, 0, 0, 1.0);
PDF_end_page($p);
PDF_begin_page($p, 595, 842);
pdf_place_image($p, $template, 0, 0, 1.0);
PDF_end_page($p);
PDF_close($p);
$buf = PDF_get_buffer($p);
$len = strlen($buf);
Header("Content-type:application/pdf");
Header("Content-Length:{$len}");
Header("Content-Disposition:inline; filename=gra2.pdf");
echo $buf;
Beispiel #5
0
pdf_restore($pdf);
/* draw minute hand */
pdf_save($pdf);
pdf_rotate($pdf, -($ltime['seconds'] / 60.0 + $ltime['minutes'] - 15.0) * 6.0);
pdf_moveto($pdf, -$radius / 10, -$radius / 20);
pdf_lineto($pdf, $radius * 0.8, 0.0);
pdf_lineto($pdf, -$radius / 10, $radius / 20);
pdf_closepath($pdf);
pdf_fill($pdf);
pdf_restore($pdf);
/* draw second hand */
pdf_setrgbcolor($pdf, 1.0, 0.0, 0.0);
pdf_setlinewidth($pdf, 2);
pdf_save($pdf);
pdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
pdf_moveto($pdf, -$radius / 5, 0.0);
pdf_lineto($pdf, $radius, 0.0);
pdf_stroke($pdf);
pdf_restore($pdf);
/* draw little circle at center */
pdf_circle($pdf, 0, 0, $radius / 30);
pdf_fill($pdf);
pdf_restore($pdf);
/* DONE */
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
// hides "Generating ..." message:
echo "<script language='JavaScript'>document.getElementById('loading').style.display = 'none';</script>";
if (!file_exists($file)) {
    ?>
Beispiel #6
0
 function _slide(&$slide)
 {
     global $pres;
     $currentPres = $_SESSION['currentPres'];
     $p = $this->objs[1];
     $middle = (int) ($this->pdf_y / 2) - 40;
     $this->pdf_cy = 25;
     // top-margin
     $this->pdf_cx = 40;
     if ($this->objs[1]->template == 'titlepage') {
         $p = $pres;
         $loc = $middle - 80 * (!empty($p->title) + !empty($p->event) + !empty($p->date) + (!empty($p->speaker) || !empty($p->email)) + !empty($p->url) + !empty($p->subtitle)) / 2;
         if (!empty($p->title)) {
             pdf_set_font($this->pdf, $this->pdf_font, -36, 'winansi');
             pdf_show_boxed($this->pdf, $p->title, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
         }
         if (!empty($p->subtitle)) {
             $loc += 50;
             pdf_set_font($this->pdf, $this->pdf_font, -22, 'winansi');
             pdf_show_boxed($this->pdf, $p->subtitle, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
         }
         if (!empty($p->event)) {
             $loc += 80;
             pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
             pdf_show_boxed($this->pdf, $p->event, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
         }
         if (!empty($p->date) && !empty($p->location)) {
             $loc += 80;
             pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
             pdf_show_boxed($this->pdf, $p->date . '. ' . $p->location, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
         } else {
             if (!empty($p->date)) {
                 $loc += 80;
                 pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
                 pdf_show_boxed($this->pdf, $p->date, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
             } else {
                 if (!empty($p->location)) {
                     $loc += 80;
                     pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
                     pdf_show_boxed($this->pdf, $p->location, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
                 }
             }
         }
         if (!empty($p->speaker) && !empty($p->email)) {
             $loc += 80;
             pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
             pdf_show_boxed($this->pdf, $p->speaker . ' <' . $p->email . '>', 10, $loc, $this->pdf_x - 20, 40, 'center', null);
         } else {
             if (!empty($p->speaker)) {
                 $loc += 80;
                 pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
                 pdf_show_boxed($this->pdf, $p->speaker, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
             } else {
                 if (!empty($p->email)) {
                     $loc += 80;
                     pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
                     pdf_show_boxed($this->pdf, ' <' . $p->email . '>', 10, $loc, $this->pdf_x - 20, 40, 'center', null);
                 }
             }
         }
         if (!empty($p->url)) {
             $loc += 80;
             pdf_set_font($this->pdf, $this->pdf_font, -30, 'winansi');
             pdf_show_boxed($this->pdf, $p->url, 10, $loc, $this->pdf_x - 20, 40, 'center', null);
         }
         if (!empty($p->copyright)) {
             pdf_moveto($this->pdf, 60, $this->pdf_y - 60);
             pdf_lineto($this->pdf, $this->pdf_x - 60, $this->pdf_y - 60);
             pdf_stroke($this->pdf);
             pdf_set_font($this->pdf, $this->pdf_font, -10, 'winansi');
             $fnt = pdf_findfont($this->pdf, $this->pdf_font, 'winansi', 0);
             $x = (int) ($this->pdf_x / 2 - pdf_stringwidth($this->pdf, $p->copyright, $fnt, -10) / 2);
             $str = str_replace('(c)', chr(0xa9), $p->copyright);
             $str = str_replace('(R)', chr(0xae), $str);
             pdf_show_xy($this->pdf, $str, $x, $this->pdf_y - 45);
         }
         $this->page_index[$this->page_number] = 'titlepage';
     } else {
         // No header on the title page
         pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi');
         $fnt = pdf_findfont($this->pdf, $this->pdf_font, 'winansi', 0);
         pdf_show_boxed($this->pdf, "Slide {$this->slideNum}/{$this->maxSlideNum}", $this->pdf_cx, $this->pdf_cy, $this->pdf_x - 2 * $this->pdf_cx, 1, 'left', null);
         if (isset($p->date)) {
             $this->d = $this->date;
         } else {
             $this->d = strftime("%B %e %Y");
         }
         $w = pdf_stringwidth($this->pdf, $this->d, $fnt, -12);
         pdf_show_boxed($this->pdf, $this->d, 40, $this->pdf_cy, $this->pdf_x - 2 * $this->pdf_cx, 1, 'right', null);
         pdf_set_font($this->pdf, $this->pdf_font, -24, 'winansi');
         pdf_show_boxed($this->pdf, strip_markups($slide->title), 40, $this->pdf_cy, $this->pdf_x - 2 * $this->pdf_cx, 1, 'center', null);
         $this->page_index[$this->page_number] = strip_markups($slide->title);
     }
     $this->pdf_cy += 30;
     if ($this->slideNum) {
         pdf_moveto($this->pdf, 40, $this->pdf_cy);
         pdf_lineto($this->pdf, $this->pdf_x - 40, $this->pdf_cy);
         pdf_stroke($this->pdf);
     }
     $this->pdf_cy += 20;
     pdf_set_text_pos($this->pdf, $this->pdf_cx, $this->pdf_cy);
 }
Beispiel #7
0
pdf_translate($pdf, $x0, $y0);
pdf_moveto($pdf, 0, -1);
pdf_lineto($pdf, 0, -11);
pdf_moveto($pdf, 121, -1);
pdf_lineto($pdf, 121, -11);
pdf_moveto($pdf, 0, 121);
pdf_lineto($pdf, 0, 131);
pdf_moveto($pdf, 121, 121);
pdf_lineto($pdf, 121, 131);
pdf_moveto($pdf, -1, 0);
pdf_lineto($pdf, -11, 0);
pdf_moveto($pdf, -1, 120);
pdf_lineto($pdf, -11, 120);
pdf_moveto($pdf, 122, 0);
pdf_lineto($pdf, 132, 0);
pdf_moveto($pdf, 122, 120);
pdf_lineto($pdf, 132, 120);
pdf_stroke($pdf);
if ($bitmap['front_resolution'] >= $cfg['image_front_cover_treshold']) {
    $pdfdfimage = pdf_load_image($pdf, 'auto', $cfg['media_dir'] . $bitmap['image_front'], '');
    pdf_fit_image($pdf, $pdfdfimage, 0, 0, 'boxsize {121 120} position {50 50} fitmethod slice');
    $hash_data .= '-' . filesize($cfg['media_dir'] . $bitmap['image_front']) . '-' . filemtime($cfg['media_dir'] . $bitmap['image_front']);
}
//  +------------------------------------------------------------------------+
//  | Close and download PDF                                                 |
//  +------------------------------------------------------------------------+
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
pdf_delete($pdf);
$filename = $album['artist'] . ' - ' . $album['album'] . '.pdf';
Beispiel #8
0
$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;
    $total += $item[1];
}
pdf_set_font($pdf, "Times-Bold", 17, winansi);
$offset += 24;
Beispiel #9
0
# pdf_example4
# a simple bar graph
// create a new pdf document
$pdf = pdf_new();
$filename = 'c:pdf_example4.pdf';
pdf_open_file($pdf, $filename);
// start a new page (Letter size)
pdf_begin_page($pdf, 612, 792);
// setup font and print hello world
pdf_set_parameter($pdf, 'FontOutline', 'Arial=c:windowsfontsarial.ttf');
$font = pdf_findfont($pdf, "Arial", "host", 1);
pdf_setfont($pdf, $font, 16);
pdf_show_xy($pdf, "Simple Bar Graph", 50, 720);
// draw the x and y axis
pdf_moveto($pdf, 50, 690);
pdf_lineto($pdf, 50, 520);
pdf_lineto($pdf, 400, 520);
pdf_stroke($pdf);
// draw the bar chart
$x = 80;
$y = 520;
$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
Beispiel #10
0
 function end_message()
 {
     $y = pdf_get_value($this->pdf, 'texty', 0) - 10;
     pdf_moveto($this->pdf, $this->wmargin, $y);
     pdf_lineto($this->pdf, $this->pw - $this->wmargin, $y);
     pdf_moveto($this->pdf, $this->wmargin, $y - 3);
     pdf_lineto($this->pdf, $this->pw - $this->wmargin, $y - 3);
     pdf_stroke($this->pdf);
     pdf_set_text_pos($this->pdf, $this->wmargin, $y - 20);
 }
function draw_star($centerx, $centery, $points, $radius, $point_size, $pdf, $filled)
{
    $inner_radius = $radius - $point_size;
    for ($i = 0; $i <= $points * 2; $i++) {
        $angle = $i * 2 * pi() / ($points * 2);
        if ($i % 2) {
            $x = $radius * cos($angle) + $centerx;
            $y = $radius * sin($angle) + $centery;
        } else {
            $x = $inner_radius * cos($angle) + $centerx;
            $y = $inner_radius * sin($angle) + $centery;
        }
        if ($i == 0) {
            pdf_moveto($pdf, $x, $y);
        } else {
            if ($i == $points * 2) {
                pdf_closepath($pdf);
            } else {
                pdf_lineto($pdf, $x, $y);
            }
        }
    }
    if ($filled) {
        pdf_fill_stroke($pdf);
    } else {
        pdf_stroke($pdf);
    }
}
    // Full Days Text //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "Full Days", 150, 100);
    // Full Days Text Above Line //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "{$full}", 125, 100);
    // Full Days Line //
    pdf_moveto($pdf, 110, 99);
    pdf_lineto($pdf, 145, 99);
    pdf_stroke($pdf);
    // Half Days Text //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "Half Days", 240, 100);
    // Half Days Text Above Line //
    pdf_setfont($pdf, $body, 10);
    pdf_show_xy($pdf, "{$half}", 215, 100);
    // Half Days Line //
    pdf_moveto($pdf, 200, 99);
    pdf_lineto($pdf, 235, 99);
    pdf_stroke($pdf);
    pdf_end_page($pdf);
}
//close it up
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
// Close up the db connection //
mysql_close($dbcnx);
header('Content-type: application/pdf');
header('Content-disposition: attachment; filename=ReportCard.pdf');
header('Content-length: ' . strlen($data));
echo $data;