Example #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);
}
 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);
 }
Example #3
0
 /**
  * Get the width of a text,
  *
  * @param string $text The text to get the width of
  * @return int The width of the text
  */
 function textWidth($text)
 {
     if ($this->_pdfFont === false) {
         return $this->_font['size'] * 0.7 * strlen($text);
     } else {
         return pdf_stringwidth($this->_pdf, $text, $this->_pdfFont, $this->_font['size']);
     }
 }
 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);
 }
Example #5
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, "");
     }
 }
 /**
  * Returns the number of required output lines
  *
  * Returns the number of lines which are required when the text
  * is output with the current parameters (font face, font size and
  * wrap method). Note that there will be no performance penalty
  * when calling this method before puttext() as the results
  * are cached in class variables. In fact, this method will
  * be called by puttext() anyway as this is the actual layout
  * engine!
  *
  * @access   public
  */
 function getrequiredlinenum()
 {
     $this->lines = array();
     $this->linewidths = array();
     // Font must be set for PDF_stringwidth()!
     $font = PDF_findfont($this->pdf, $this->fontface, 'host', 0);
     PDF_setfont($this->pdf, $font, $this->fontsize);
     if ($this->wrapmethod == "WORD" || $this->wrapmethod == "WORDSTRICT") {
         // Word orientated line wrapping
         $words = split(" +", $this->buffer);
         $i = 0;
         while ($i < sizeof($words)) {
             $currentline = "";
             $nextword = $words[$i];
             do {
                 $currentline .= $nextword;
                 $nextword = " " . $words[++$i];
             } while (PDF_stringwidth($this->pdf, $currentline . $nextword) <= $this->width && $i < sizeof($words));
             if (PDF_stringwidth($this->pdf, $currentline) > $this->width) {
                 // Not even one word fits into the line
                 // Wrapping mode "word" means to apply char wrapping,
                 // wrapping mode "wordstrict" means to leave
                 // the word untouched and output it violating the
                 // border
                 if ($this->wrapmethod == "WORD") {
                     $charnum = 0;
                     do {
                         $charnum++;
                     } while (pdf_stringwidth($this->pdf, substr($currentline, 0, $charnum + 1)) <= $this->width);
                     // Save the rest of the word for the next line
                     $words[--$i] = substr($currentline, $charnum);
                     // Cut off the line so that it fits in
                     $currentline = substr($currentline, 0, $charnum);
                 }
             }
             $linewidth = pdf_stringwidth($this->pdf, $currentline);
             array_push($this->lines, $currentline);
             array_push($this->linewidths, $linewidth);
         }
     } else {
         // Character orientated line wrapping
         $buf =& $this->buffer;
         $i = 0;
         while ($i < strlen($buf)) {
             // Remove leading blanks
             while (substr($buf, $i, 1) == " ") {
                 $i++;
             }
             $charnum = 0;
             do {
                 $charnum++;
             } while (pdf_stringwidth($this->pdf, substr($buf, $i, $charnum + 1)) <= $this->width && $i + $charnum < strlen($buf));
             $line = substr($buf, $i, $charnum);
             // Remove trailing blanks
             $line = ereg_replace(" *\$", "", $line);
             $linewidth = pdf_stringwidth($this->pdf, $line);
             array_push($this->lines, $line);
             array_push($this->linewidths, $linewidth);
             $i += $charnum;
         }
     }
     $this->layoutvalid = true;
     return sizeof($this->lines);
 }
Example #7
0
 function getTextWidth($text, $style)
 {
     return pdf_stringwidth($this->pdf, $text, $this->font, $style['font']) / $this->width;
 }
Example #8
0
 function add_link($url, $caption)
 {
     $oh = pdf_get_value($this->pdf, 'texty', 0);
     pdf_show($this->pdf, $caption);
     $y = pdf_get_value($this->pdf, 'texty', 0);
     $w = pdf_get_value($this->pdf, 'textx', 0);
     $ow = pdf_get_value($this->pdf, 'textx', 0) - pdf_stringwidth($this->pdf, $caption);
     pdf_set_border_style($this->pdf, 'dashed', 0);
     pdf_add_weblink($this->pdf, $ow, $oh, $w, $oh + 12, $url);
 }
 pdf_rect($pdf, $inset - $inner, $inset - $inner, $width - 2 * ($inset - $inner), $height - 2 * ($inset - $inner));
 pdf_stroke($pdf);
 //draw main border $border points wide
 pdf_setlinewidth($pdf, $border);
 pdf_rect($pdf, $inset + $border / 2, $inset + $border / 2, $width - 2 * ($inset + $border / 2), $height - 2 * ($inset + $border / 2));
 pdf_stroke($pdf);
 pdf_setlinewidth($pdf, 1.0);
 // draw inner border
 pdf_rect($pdf, $inset + $border + $inner, $inset + $border + $inner, $width - 2 * ($inset + $border + $inner), $height - 2 * ($inset + $border + $inner));
 pdf_stroke($pdf);
 // add heading
 $font = pdf_findfont($pdf, $fontname, 'host', 0);
 if ($font) {
     pdf_setfont($pdf, $font, 48);
 }
 $startx = ($width - pdf_stringwidth($pdf, 'PHP Certification', $font, '12')) / 2;
 pdf_show_xy($pdf, 'PHP Certification', $startx, 490);
 // add text
 $font = pdf_findfont($pdf, $fontname, 'host', 0);
 if ($font) {
     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);