Ejemplo n.º 1
0
function center($s, $y, $size, $fontname = "Times-Roman", $outline = 0)
{
    global $pdf, $font, $width;
    pdf_set_value($pdf, "textrendering", $outline);
    $font = pdf_findfont($pdf, $fontname, "iso8859-2");
    pdf_setfont($pdf, $font, $size);
    $w = pdf_stringwidth($pdf, $s);
    pdf_show_xy($pdf, $s, ($width - $w) / 2, $y);
}
Ejemplo n.º 2
0
 function _show_watermark($watermark)
 {
     $font = $this->findfont('Helvetica', 'iso-8859-1');
     pdf_setfont($this->pdf, $font, 100);
     $x = $this->left + $this->width / 2;
     $y = $this->bottom + $this->height / 2 + $this->offset;
     pdf_set_value($this->pdf, "textrendering", 1);
     pdf_translate($this->pdf, $x, $y);
     pdf_rotate($this->pdf, 60);
     pdf_show_xy($this->pdf, $watermark, -pdf_stringwidth($this->pdf, $watermark, $font, 100) / 2, -50);
 }
Ejemplo n.º 3
0
 /**
  * Writes text
  *
  * Parameter array:
  * 'x': int X-point of text
  * 'y': int Y-point of text
  * 'text': string The text to add
  * 'alignment': array [optional] Alignment
  * 'color': mixed [optional] The color of the text
  */
 function addText($params)
 {
     $x = $this->_getX($params['x']);
     $y = $this->_getY($params['y']);
     $text = $params['text'];
     $color = isset($params['color']) ? $params['color'] : false;
     $alignment = isset($params['alignment']) ? $params['alignment'] : false;
     $this->_setFont();
     $textWidth = $this->textWidth($text);
     $textHeight = $this->textHeight($text);
     if (!is_array($alignment)) {
         $alignment = array('vertical' => 'top', 'horizontal' => 'left');
     }
     if (!isset($alignment['vertical'])) {
         $alignment['vertical'] = 'top';
     }
     if (!isset($alignment['horizontal'])) {
         $alignment['horizontal'] = 'left';
     }
     if ($alignment['horizontal'] == 'right') {
         $x = $x - $textWidth;
     } elseif ($alignment['horizontal'] == 'center') {
         $x = $x - $textWidth / 2;
     }
     if ($alignment['vertical'] == 'top') {
         $y = $y + $textHeight;
     } elseif ($alignment['vertical'] == 'center') {
         $y = $y + $textHeight / 2;
     }
     if ($color === false && isset($this->_font['color'])) {
         $color = $this->_font['color'];
     }
     pdf_show_xy($this->_pdf, $text, $this->_getX($x), $this->_getY($y));
     parent::addText($params);
 }
Ejemplo n.º 4
0
<?php

$p = PDF_new();
PDF_open_file($p);
PDF_begin_page($p, 595, 842);
$im = pdf_open_jpeg($p, "php-big.jpg");
pdf_place_image($p, $im, 200, 700, 1.0);
pdf_place_image($p, $im, 200, 600, 0.75);
pdf_place_image($p, $im, 200, 535, 0.5);
pdf_place_image($p, $im, 200, 501, 0.25);
pdf_place_image($p, $im, 200, 486, 0.1);
$x = pdf_get_value($p, "imagewidth", $im);
$y = pdf_get_value($p, "imageheight", $im);
pdf_close_image($p, $im);
$font = PDF_findfont($p, "Times-Bold", "host", 0);
PDF_setfont($p, $font, 28.0);
pdf_show_xy($p, "{$x} by {$y}", 25, 800);
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=coords.pdf");
echo $buf;
PDF_delete($p);
 function _show_watermark()
 {
     if (is_null($this->_watermark) || $this->_watermark == "") {
         return;
     }
     $font = $this->_control_font();
     pdf_setfont($this->pdf, $font, 100);
     $x = $this->left + $this->width / 2;
     $y = $this->bottom + $this->height / 2 + $this->offset;
     pdf_set_value($this->pdf, "textrendering", 1);
     pdf_translate($this->pdf, $x, $y);
     pdf_rotate($this->pdf, 60);
     pdf_show_xy($this->pdf, $this->_watermark, -pdf_stringwidth($this->pdf, $this->_watermark, $font, 100) / 2, -50);
 }
Ejemplo n.º 6
0
<?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;
Ejemplo n.º 7
0
<?php

// create handle for new PDF document
$pdf = pdf_new();
// open a file
pdf_open_file($pdf, "philosophy.pdf");
// start a new page (A4)
pdf_begin_page($pdf, 595, 842);
// get and use a font object
$arial = pdf_findfont($pdf, "Arial", "host", 1);
pdf_setfont($pdf, $arial, 10);
// print text
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,", 50, 750);
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50, 730);
// end page
pdf_end_page($pdf);
// close and save file
pdf_close($pdf);
Ejemplo n.º 8
0
 function _link(&$link)
 {
     if (empty($link->text)) {
         $link->text = preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $link->href);
     }
     if (!empty($link->leader)) {
         $leader = preg_replace('/:-:(.*?):-:/e', '$this->pres->\\1', $link->leader);
     } else {
         $leader = '';
     }
     if (!empty($link->text)) {
         $this->pdf_cy = pdf_get_value($this->pdf, "texty", null) + 10;
         pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi');
         $fnt = pdf_findfont($this->pdf, $this->pdf_font, 'winansi', 0);
         if (strlen($leader)) {
             $lx = pdf_stringwidth($this->pdf, $leader, $fnt, -12);
         } else {
             $lx = 0;
         }
         $dx = pdf_stringwidth($this->pdf, $link->text, $fnt, -12);
         $cw = pdf_stringwidth($this->pdf, 'm', $fnt, -12);
         // em unit width
         switch ($link->align) {
             case 'center':
                 $x = (int) ($this->pdf_x / 2 - $dx / 2 - $lx / 2);
                 break;
             case 'right':
                 $x = $this->pdf_x - $this->pdf_cx - $dx - $lx - 15;
                 break;
             case 'left':
             default:
                 $x = $this->pdf_cx;
                 break;
         }
         if ($link->marginleft) {
             $x += (int) ((double) $link->marginleft * $cw);
         }
         pdf_add_weblink($this->pdf, $x + $lx, $this->pdf_y - $this->pdf_cy - 3, $x + $dx + $lx, $this->pdf_y - $this->pdf_cy + 12, $link->text);
         pdf_show_xy($this->pdf, strip_markups($leader) . strip_markups($link->text), $x, $this->pdf_cy);
         pdf_continue_text($this->pdf, "");
     }
 }
Ejemplo n.º 9
0
$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
function hex2rgb($hex)
{
Ejemplo n.º 10
0
}
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;
pdf_show_xy($pdf, 'Total', 30, $y - $offset);
pdf_show_boxed($pdf, '$' . number_format($total, 2), $x - 55, $y - $offset, 0, 0, 'right');
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header("Content-disposition: inline; filename=invoice.pdf");
header("Content-length: " . strlen($data));
echo $data;
Ejemplo n.º 11
0
<?php

define('PAGE_WIDTH', 612);
define('PAGE_HEIGHT', 792);
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_begin_page($pdf, PAGE_WIDTH, PAGE_HEIGHT);
$font = pdf_findfont($pdf, "Helvetica", "auto", false);
pdf_setfont($pdf, $font, 30);
pdf_show_xy($pdf, "PHP Developer's Handbook", 10, PAGE_HEIGHT - 40);
pdf_setfont($pdf, $font, 12);
pdf_show_xy($pdf, "Hello, World! Using PDFLib and PHP", 10, PAGE_HEIGHT - 55);
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header("Content-disposition: inline; filename=output.pdf");
header("Content-length: " . strlen($data));
echo $data;
Ejemplo n.º 12
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_setfont($pdf, $font, 26);
 }
 $startx = 70;
 pdf_show_xy($pdf, 'This is to certify that:', $startx, 430);
 pdf_show_xy($pdf, strtoupper($name), $startx + 90, 391);
 $font = pdf_findfont($pdf, $fontname, 'host', 0);
 if ($font) {
     pdf_setfont($pdf, $font, 20);
 }
 pdf_show_xy($pdf, 'has demonstrated that they are certifiable ' . 'by passing a rigorous exam', $startx, 340);
 pdf_show_xy($pdf, 'consisting of three multiple choice questions.', $startx, 310);
 pdf_show_xy($pdf, "{$name} obtained a score of {$score}" . '%.', $startx, 260);
 pdf_show_xy($pdf, 'The test was set and overseen by the ', $startx, 210);
 pdf_show_xy($pdf, 'Fictional Institute of PHP Certification', $startx, 180);
 pdf_show_xy($pdf, "on {$date}.", $startx, 150);
 pdf_show_xy($pdf, 'Authorised by:', $startx, 100);
 // add bitmap signature image
 $signature = pdf_load_image($pdf, 'png', '/Program Files/Apache Software Foundation/Apache2.2/htdocs/phpmysql4e/chapter33/signature.png', '');
 pdf_fit_image($pdf, $signature, 200, 75, '');
 pdf_close_image($pdf, $signature);
 // set up colors for ribbon
 pdf_setcolor($pdf, 'fill', 'rgb', 0, 0, 0.4, 0);
 // dark blue
 pdf_setcolor($pdf, 'stroke', 'rgb', 0, 0, 0, 0);
 // black
 // draw ribbon 1
 pdf_moveto($pdf, 630, 150);
 pdf_lineto($pdf, 610, 55);
 pdf_lineto($pdf, 632, 69);
 pdf_lineto($pdf, 646, 49);
 pdf_lineto($pdf, 666, 150);
Ejemplo n.º 14
0
//pdf_set_value($pdf, "textrendering", 1);
$jpeg_image = pdf_open_image_file($pdf, "jpeg", "images/logo2os.jpg");
pdf_place_image($pdf, $jpeg_image, 200, $i_top, 1.0);
pdf_close_image($pdf, $jpeg_image);
/*$jpeg_image = pdf_open_image_file($pdf, "jpeg", "images/top1.jpg");
pdf_place_image($pdf, $jpeg_image, 300, $i_top+20, 0.5);
pdf_close_image($pdf, $jpeg_image);
$jpeg_image = pdf_open_image_file($pdf, "jpeg", "images/top4.jpg");
pdf_place_image($pdf, $jpeg_image, 301, $i_top-10, 0.5);
pdf_close_image($pdf, $jpeg_image);*/
$i_top -= 50;
pdf_show_xy($pdf, "Company Name", $i_left, $i_top);
pdf_show_xy($pdf, "[Company Name]", $i_left + $i_offset, $i_top);
$i_top -= 30;
pdf_show_xy($pdf, "Address", $i_left, $i_top);
pdf_show_xy($pdf, "[Address]", $i_left + $i_offset, $i_top);
/*if ($str_city != "") {
	$i_top -= 20;
	pdf_show_xy($pdf, $str_city, $i_left+$i_offset, $i_top); 
}
if ($str_state != "") {
	$i_top -= 20;
	pdf_show_xy($pdf, $str_state, $i_left+$i_offset, $i_top); 
}
if ($str_country != "") {
	$i_top -= 20;
	pdf_show_xy($pdf, $str_country, $i_left+$i_offset, $i_top); 
}
if ($str_zip_code != "") {
	$i_top -= 20;
	pdf_show_xy($pdf, $str_zip_code, $i_left+$i_offset, $i_top); 
Ejemplo n.º 15
0
    // 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;