/**
  * Render the tag content.
  *
  * @return void
  */
 public function close()
 {
     $this->pdf->setFont($this->font, $this->fontStyle, $this->fontSize);
     $fontColor = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->setTextColor($fontColor['r'], $fontColor['g'], $fontColor['b']);
     $this->pdf->MultiCell(190, $this->lineHeight, $this->content, false, $this->textAlign, false);
 }
 /**
  * Constructor.
  *
  * Parse the tag attributes and add the new line to the document.
  *
  * @param array $tagProperties tag properties
  * @return void
  */
 public function __construct($tagProperties)
 {
     $pdf = Pdf::singleton();
     $lineColor = $tagProperties['LINECOLOR'];
     if ($lineColor != '') {
         $drawColor = Xml2Pdf::convertColor($lineColor);
         $pdf->SetDrawColor($drawColor['r'], $drawColor['g'], $drawColor['b']);
     }
     $lineWidth = $tagProperties['LINEWIDTH'];
     if ($lineWidth != '') {
         $currentLW = $pdf->LineWidth;
         $pdf->SetLineWidth((double) $lineWidth);
     }
     $x1 = $this->mathEval($tagProperties['LEFT']);
     $x2 = $this->mathEval($tagProperties['RIGHT']);
     $y1 = $this->mathEval($tagProperties['TOP']);
     $y2 = $this->mathEval($tagProperties['TOP']);
     $pdf->Line((double) $x1, (double) $y1, (double) $x2, (double) $y2);
     $y1 = $this->mathEval($tagProperties['BOTTOM']);
     $y2 = $y1;
     $pdf->Line((double) $x1, (double) $y1, (double) $x2, (double) $y2);
     //$x1 = $this->mathEval($tagProperties['LEFT']);
     $x2 = $x1;
     $y1 = $this->mathEval($tagProperties['TOP']);
     $y2 = $this->mathEval($tagProperties['BOTTOM']);
     $pdf->Line((double) $x1, (double) $y1, (double) $x2, (double) $y2);
     $x1 = $this->mathEval($tagProperties['RIGHT']);
     $x2 = $x1;
     //$y1 = $this->mathEval($tagProperties['TOP']);
     //$y2 = $this->mathEval($tagProperties['BOTTOM']);
     $pdf->Line((double) $x1, (double) $y1, (double) $x2, (double) $y2);
     if ($lineWidth != '') {
         $pdf->SetLineWidth($currentLW);
     }
 }
 public function __construct($tagProperties)
 {
     $pdf = Pdf::singleton();
     $x = $tagProperties['LEFT'];
     $y = $tagProperties['TOP'];
     $w = $tagProperties['WIDTH'];
     $h = $tagProperties['HEIGHT'];
     $r = $tagProperties['RADIUS'];
     $style = $tagProperties['STYLE'];
     $angle = $tagProperties['ANGLE'];
     $lineColor = $tagProperties['LINECOLOR'];
     if ($lineColor != '') {
         $drawColor = Xml2Pdf::convertColor($lineColor);
         $pdf->SetDrawColor($drawColor['r'], $drawColor['g'], $drawColor['b']);
     }
     $lineWidth = $tagProperties['LINEWIDTH'];
     if ($lineWidth != '') {
         $current = $pdf->LineWidth;
         $pdf->SetLineWidth((double) $lineWidth);
     }
     $pdf->RoundedRect($x, $y, $w, $h, $r, $angle, $style);
     if ($lineWidth != '') {
         $pdf->SetLineWidth($current);
     }
 }
 /**
  * Constructor
  * 
  * Parse the tag properties.
  *
  * @param array $attributes tag attributes
  * @param object $parentTag object xml2pdf_tag_line
  * @return void 
  */
 public function __construct(&$attributes, $parentTag)
 {
     if (!isset($attributes['X']) || !isset($attributes['Y'])) {
         Xml2Pdf::showError('Tag point must have x and y attributes.');
     }
     $parentTag->graph->data[$parentTag->legend]['x'][] = $attributes['X'];
     $parentTag->graph->data[$parentTag->legend]['y'][] = $attributes['Y'];
 }
示例#5
0
 /**
  * Show table title.
  *
  * @return void 
  */
 public function render()
 {
     // set colors
     $borderColor = Xml2Pdf::convertColor($this->borderColor);
     $this->pdf->SetDrawColor($borderColor["r"], $borderColor["g"], $borderColor["b"]);
     $fillColor = Xml2Pdf::convertColor($this->fillColor);
     $this->pdf->SetFillColor($fillColor["r"], $fillColor["g"], $fillColor["b"]);
     $fontColor = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->setTextColor($fontColor["r"], $fontColor["g"], $fontColor["b"]);
     $this->pdf->SetFont($this->font, $this->fontStyle, $this->fontSize);
     // Save the current position
     $x = $this->pdf->GetX();
     $y = $this->pdf->GetY();
     $this->pdf->MultiCell($this->table->width, $this->lineHeight, $this->content, $this->border, $this->textAlign, $this->fill);
 }
示例#6
0
 /**
  * Constructor.
  *
  * Parse the tag attributes
  *
  * @param array $tagAttributes tag attributes
  * @return void
  */
 public function __construct($tagAttributes)
 {
     parent::__construct($tagAttributes);
     $left = $top = 0;
     if (isset($tagAttributes['REF'])) {
         $ref = $tagAttributes['REF'];
     }
     if (isset($tagAttributes['URL'])) {
         $url = $tagAttributes['URL'];
     }
     if (isset($tagAttributes['NAME'])) {
         $name = $tagAttributes['NAME'];
     }
     if (isset($tagAttributes['LEFT'])) {
         $left = $tagAttributes['LEFT'];
     }
     if (isset($tagAttributes['TOP'])) {
         $top = $tagAttributes['TOP'];
     }
     // par default les liens sont en bleu et souligné
     if (!isset($tagAttributes['FONTCOLOR'])) {
         $this->fontColor = '#0000FF';
     }
     if (!isset($tagAttributes['FONTSTYLE'])) {
         $this->fontStyle = 'U';
     }
     // positionne le curseur
     if ($left > 0) {
         $this->pdf->SetX($left);
     }
     if ($top > 0) {
         $this->pdf->SetY($top);
     }
     $this->pdf->setFont($this->font, $this->fontStyle, $this->fontSize);
     $color = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->setTextColor($color['r'], $color['g'], $color['b']);
     if (isset($ref) && isset($name)) {
         if (!isset($this->pdf->linksIds[$ref])) {
             $this->pdf->linksIds[$ref] = $this->pdf->AddLink();
         }
         $url = $this->pdf->linksIds[$ref];
     }
     $this->pdf->Write($this->pdf->defaultLn, $name, $url);
 }
示例#7
0
 /**
  * Search the styles information and put them.
  *
  * @return void
  */
 private function _setStyle()
 {
     $fontStyle = '';
     $fontColor = null;
     $font = null;
     $fontSize = null;
     //$indentSetted = false;
     $count = count($this->styleStack);
     for ($i = $count - 1; $i >= 0; $i--) {
         if (empty($fontColor) && isset($this->styleStack[$i]['color'])) {
             $fontColor = $this->styleStack[$i]['color'];
         }
         if (empty($font) && isset($this->styleStack[$i]['font'])) {
             $font = $this->styleStack[$i]['font'];
         }
         if (empty($fontSize) && isset($this->styleStack[$i]['font-size'])) {
             $fontSize = $this->styleStack[$i]['font-size'];
         }
         if (isset($this->styleStack[$i]['font-style']) && !empty($this->styleStack[$i]['font-style'])) {
             if (false !== strpos($fontStyle, trim($this->styleStack[$i]['font-style']))) {
                 continue;
             }
             $fontStyle .= trim($this->styleStack[$i]['font-style']);
         }
     }
     $this->pdf->setFont($font, $fontStyle, $fontSize);
     $fontColor = Xml2Pdf::convertColor($fontColor);
     $this->pdf->setTextColor($fontColor['r'], $fontColor['g'], $fontColor['b']);
 }
 /**
  * Draw a curve type graph
  *
  * @param Object $graph Object Xml2Pdf_Tag_graph
  * @return void
  */
 public static function render($graph)
 {
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $graph->setLegends();
     $XPage = $graph->pdf->GetX();
     $YPage = $graph->pdf->GetY();
     $marge = 2;
     $hDiag = $graph->height;
     $lDiag = $graph->width - $graph->legendWidth - 5 * $marge - 5;
     $XDiag = $XPage + $marge;
     $YDiag = $YPage + $marge;
     $xMax = 0;
     $yMax = 0;
     foreach ($graph->data as $line) {
         if ($xMax < max($line['x'])) {
             $xMax = max($line['x']);
         }
         if ($yMax < max($line['y'])) {
             $yMax = max($line['y']);
         }
     }
     $uniteX = $lDiag / $xMax;
     $uniteY = $hDiag / ($yMax + 5);
     $graph->pdf->SetLineWidth(0.2);
     $graph->pdf->Rect($XDiag, $YDiag, $lDiag, $hDiag);
     //reperes
     $tab = Xml2Pdf::ConvertColor('#dcdcdc');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     $deltaX = $lDiag / $graph->nbIndRepere;
     $deltaY = $hDiag / $graph->nbIndRepere;
     $graph->pdf->SetLineWidth(0.2);
     for ($i = 0; $i <= $graph->nbIndRepere; $i++) {
         if ($i > 0 && $i < $graph->nbIndRepere) {
             $graph->pdf->Line($XDiag, $YDiag + $i * $deltaY, $XDiag + $lDiag, $YDiag + $i * $deltaY);
             $graph->pdf->Line($XDiag + $i * $deltaX, $YDiag, $XDiag + $i * $deltaX, $YDiag + $hDiag);
         }
         $valY = floor(($hDiag - $i * $deltaY) / $uniteY);
         $valX = floor($i * $deltaX / $uniteX);
         $lenY = $graph->pdf->GetStringWidth($valY);
         $lenX = $graph->pdf->GetStringWidth($valX);
         $graph->pdf->Text($XDiag - $lenY - 2, $YDiag + $i * $deltaY, $valY);
         $graph->pdf->Text($XDiag + $i * $deltaX - $lenX / 2, $YDiag + $hDiag + 5, $valX);
     }
     //lignes
     $nbPoint = 0;
     $ligne = 0;
     $graph->pdf->SetLineWidth(0.5);
     foreach ($graph->data as $key => $line) {
         if ($graph->colors[$key] == null) {
             $graph->colors[$key] = Xml2Pdf::getColor();
         }
         $tab = Xml2Pdf::ConvertColor($graph->colors[$key]);
         $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
         $nbPoint = min(count($line['x']), count($line['y']));
         for ($i = 0; $i < $nbPoint - 1; $i++) {
             $xd = $XDiag + $line['x'][$i] * $uniteX;
             $yd = $YDiag + $hDiag - $line['y'][$i] * $uniteY;
             $xf = $XDiag + $line['x'][$i + 1] * $uniteX;
             $yf = $YDiag + $hDiag - $line['y'][$i + 1] * $uniteY;
             $graph->pdf->Line($xd, $yd, $xf, $yf);
         }
         $ligne++;
     }
     //Légende
     $graph->pdf->SetLineWidth(0.2);
     $tab = Xml2Pdf::ConvertColor('#000000');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $x1 = $XPage + $lDiag + 4 * $marge;
     $x2 = $x1 + 5 + $marge;
     $y1 = $YDiag + 3 * $marge;
     for ($i = 0; $i < $graph->nbVal; $i++) {
         $tab = Xml2Pdf::ConvertColor($graph->colors[$graph->legends[$i]]);
         $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
         $graph->pdf->Rect($x1, $y1 + $i * $marge * 2, 5, 5, 'DF');
         $graph->pdf->SetXY($x2, $y1 + $i * $marge * 2);
         $graph->pdf->Cell(0, 5, $graph->legends[$i]);
         $y1 += $marge;
     }
 }
 /**
  * Close the tag and launch the render.
  *
  * Calcul the bar code length and the real coordonate then launch
  * the traitment to draw the bar code.
  *
  * @return void 
  */
 public function close()
 {
     if ($this->position == 'relative') {
         $this->x += $this->pdf->GetX();
         $this->y += $this->pdf->GetY();
     }
     //$clsName = $this->getRenderPlugin();
     $norm = strtolower($this->norm);
     $clsName = Xml2Pdf::searchPlugin($norm, 'barcode');
     call_user_func(array($clsName, 'render'), $this);
     return true;
 }
示例#10
0
 /**
  * Render the line.
  *
  * @return void 
  */
 public function render()
 {
     if (!$this->columnsWidth) {
         // première ligne, on calcule la largeur des colonnes.
         $this->_calculColumnsWidth();
     }
     $columnsProperties = array('font', 'fontSize', 'fontStyle', 'fontColor', 'fill', 'fillColor', 'border', 'borderColor', 'textAlign', 'lineHeight');
     // paramétrage des colonnes de la ligne
     $columnsWidth = array_reverse($this->columnsWidth);
     foreach ($this->columns as $column) {
         $height = 0;
         // définies les propriétés non définie de la colonne
         foreach ($columnsProperties as $property) {
             if (!isset($column->{$property})) {
                 $column->{$property} = $this->{$property};
             }
         }
         $column->width = array_pop($columnsWidth);
         // positionne les infos de police et couleur
         $borderColor = Xml2Pdf::convertColor($this->borderColor);
         $this->pdf->SetDrawColor($borderColor["r"], $borderColor["g"], $borderColor["b"]);
         $fillColor = Xml2Pdf::convertColor($this->fillColor);
         $this->pdf->SetFillColor($fillColor["r"], $fillColor["g"], $fillColor["b"]);
         $fontColor = Xml2Pdf::convertColor($this->fontColor);
         $this->pdf->setTextColor($fontColor["r"], $fontColor["g"], $fontColor["b"]);
         $this->pdf->SetFont($this->font, $this->fontStyle, $this->fontSize);
     }
     // calcule la hauteur de la ligne
     $this->_calculRowHeight();
     if ($this->pdf->getY() + $this->height >= $this->pdf->fh - $this->pdf->bMargin) {
         $this->pdf->AddPage();
         //@todo if in th and tt exist write tt
     }
     // affiche les colonnes
     foreach ($this->columns as $column) {
         $this->_renderColumn($column);
     }
     // positionne le curseur pour la ligne suivante
     $this->pdf->Ln($this->height);
     $this->pdf->setX($this->table->left);
 }
示例#11
0
 /**
  * Reset all values.
  *
  * Reset all values using the curent page values.
  *
  * @return void 
  * @access public
  */
 public function resetAllValues()
 {
     $dc = Xml2Pdf::convertColor($this->pageDrawColor);
     $fc = Xml2Pdf::convertColor($this->pageFillColor);
     $this->SetDrawColor($dc["r"], $dc["g"], $dc["b"]);
     $this->SetFillColor($fc["r"], $fc["g"], $fc["b"]);
     $this->resetFont();
 }
示例#12
0
 /**
  * Reset header values.
  *
  * @return void
  */
 private function _resetValues()
 {
     $dc = array();
     // drawColor
     $fc = array();
     // fillColor
     $dc = Xml2Pdf::convertColor($this->borderColor);
     $fc = Xml2Pdf::convertColor($this->fillColor);
     $this->pdf->SetDrawColor($dc['r'], $dc['g'], $dc['b']);
     $this->pdf->SetFillColor($fc['r'], $fc['g'], $fc['b']);
     $color = array();
     $color = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->SetTextColor($color['r'], $color['g'], $color['b']);
     $this->pdf->SetFont($this->font, $this->fontStyle, $this->fontSize);
 }
示例#13
0
 function create_page()
 {
     global $_CAMILA;
     require_once CAMILA_LIB_DIR . 'xml-2-pdf/Xml2Pdf.php';
     require_once CAMILA_LIB_DIR . 'minitemplator/MiniTemplator.class.php';
     $xmlfile = CAMILA_TMPL_DIR . '/' . $_CAMILA['lang'] . '/' . $_REQUEST['camila_xml2pdf'];
     $xml = '';
     $t = new MiniTemplator();
     $t->readTemplateFromFile($xmlfile);
     if ($_REQUEST['camila_xml2pdf_checklist_options_0'] != 'y') {
         $format = camila_get_locale_date_adodb_format();
         $text = date($format);
         $t->setVariable(camila_get_translation('camila.export.template.date'), isUTF8($text) ? utf8_decode($text) : $text, true);
         $text = date($format . ' H:i');
         $t->setVariable(camila_get_translation('camila.export.template.timestamp'), isUTF8($text) ? utf8_decode($text) : $text, true);
     }
     $i = 0;
     while (isset($this->element[$i])) {
         $page_element = $this->element[$i];
         switch ($page_element->get_elementtype()) {
             case HAW_FORM:
                 $i = 0;
                 while (isset($page_element->element[$i])) {
                     $form_element = $page_element->element[$i];
                     $form_fieldname = substr($form_element->name, strlen($_CAMILA['datagrid_form']->name) + 1);
                     $form_label = $_CAMILA['datagrid_form']->fields[$form_fieldname]->title;
                     switch ($form_element->get_elementtype()) {
                         //case HAW_IMAGE:
                         //case HAW_RADIO:
                         //case HAW_RULE:
                         case HAW_HIDDEN:
                         case HAW_INPUT:
                         case HAW_TEXTAREA:
                             $text = html_entity_decode($form_element->value);
                             for ($ii = 0; $ii < $form_element->br - 1; $ii++) {
                                 $text .= "\n";
                             }
                             $t->setVariable($form_element->label, isUTF8($text) ? utf8_decode($text) : $text, true);
                             $t->setVariable($form_label, isUTF8($text) ? utf8_decode($text) : $text, true);
                             break;
                         case HAW_SELECT:
                             foreach ($form_element->options as $key => $value) {
                                 if ($value['value'] == $form_element->value) {
                                     $text = $value['label'];
                                 }
                             }
                             $text = html_entity_decode($text);
                             $t->setVariable($form_element->label, isUTF8($text) ? utf8_decode($text) : $text, true);
                             $t->setVariable($form_label, isUTF8($text) ? utf8_decode($text) : $text, true);
                             break;
                         case HAW_CHECKBOX:
                             if (!$form_element->is_checked()) {
                                 break;
                             }
                             //$text = html_entity_decode($form_element->label);
                             $nl = 1;
                             if ($form_element->br > 0) {
                                 $nl = $form_element->br;
                             }
                             for ($ii = 0; $ii < $nl; $ii++) {
                                 $text .= "\n";
                             }
                             $t->setVariable($form_element->name, isUTF8($text) ? utf8_decode($text) : $text, true);
                             $t->setVariable($form_label, isUTF8($text) ? utf8_decode($text) : $text, true);
                             break;
                         case HAW_PLAINTEXT:
                             break;
                     }
                     $i++;
                 }
                 $t->addBlock('form');
                 break;
             case HAW_PLAINTEXT:
                 if ($this->element[$i]->text == camila_get_translation('camila.nodatafound') && $_CAMILA['datagrid_nodata'] == 1) {
                     $rowsperpage = 0;
                     if ($t->blockExists('row1')) {
                         $rowsperpage = 1;
                         while ($t->blockExists('row' . ($rowsperpage + 1))) {
                             $rowsperpage++;
                         }
                         if ($rowsperpage > 0) {
                             for ($ii = 0; $ii < $rowsperpage; $ii++) {
                                 $t->addBlock('row' . ($ii + 1));
                             }
                             $t->addBlock('table');
                         }
                     }
                 }
                 break;
             case HAW_LINK:
                 $link = $this->element[$i];
                 for ($ii = 0; $ii < $link->br; $ii++) {
                     $suffix .= "\n";
                 }
                 //$this->pdf_text(isUTF8($link->label) ? utf8_decode($link->label).$suffix : $link->label.$suffix);
                 break;
             case HAW_TABLE:
                 $table = $this->element[$i];
                 $cols = array();
                 $rowsperpage = 0;
                 $rownum = 1;
                 $pagnum = 1;
                 $multitable = false;
                 if ($t->blockExists('row1')) {
                     $multitable = true;
                     $rowsperpage = 1;
                     while ($t->blockExists('row' . ($rowsperpage + 1))) {
                         $rowsperpage++;
                     }
                 }
                 if ($_REQUEST['camila_xml2pdf_checklist_options_0'] != 'y') {
                     $row = $table->row[0];
                     for ($b = 0; $b < $row->number_of_columns; $b++) {
                         $column = $row->column[$b];
                         $cols[$b] = strtolower($column->text);
                     }
                     $t->setVariable(camila_get_translation('camila.xml2pdf.table.totalrows'), intval($table->number_of_rows) - 1);
                     for ($a = 1; $a < $table->number_of_rows; $a++) {
                         $row = $table->row[$a];
                         for ($b = 0; $b < $row->number_of_columns; $b++) {
                             $column = $row->column[$b];
                             if (is_object($column) && $column->get_elementtype() == HAW_PLAINTEXT) {
                                 $text = $column->get_text();
                             }
                             if (is_object($column) && $column->get_elementtype() == HAW_LINK) {
                                 $text = $column->get_label();
                             }
                             $t->setVariable($cols[$b], isUTF8($text) ? utf8_decode($text) : $text, true);
                             $t->setVariable(camila_get_translation('camila.xml2pdf.table.row.num'), $a);
                         }
                         if (!$multitable) {
                             $t->addBlock('row');
                         } else {
                             $t->addBlock('row' . $rownum);
                         }
                         $rownum++;
                         if ($rownum > $rowsperpage) {
                             $rownum = 1;
                             $pagnum++;
                             $t->addBlock('table');
                         }
                     }
                     if (!$multitable || $rownum > 1 && $rownum <= $rowsperpage || $multitable && $pagnum == 1) {
                         $t->addBlock('table');
                     }
                 } else {
                     if ($rowsperpage > 0) {
                         for ($ii = 0; $ii < $rowsperpage; $ii++) {
                             $t->addBlock('row' . ($ii + 1));
                         }
                         $t->addBlock('table');
                     }
                 }
                 $a = 1;
                 $row = $table->row[$a];
                 for ($b = 0; $b < $row->number_of_columns; $b++) {
                     $column = $row->column[$b];
                     if (is_object($column) && $column->get_elementtype() == HAW_PLAINTEXT) {
                         $text = $column->get_text();
                     }
                     if (is_object($column) && $column->get_elementtype() == HAW_LINK) {
                         $text = $column->get_label();
                     }
                     $t->setVariable($cols[$b], isUTF8($text) ? utf8_decode($text) : $text, true);
                     $t->setVariable(camila_get_translation('camila.xml2pdf.table.row.num'), $a);
                 }
                 break;
         }
         $i++;
     }
     $t->generateOutputToString($xml);
     $obj = new Xml2Pdf($xml);
     $pdf = $obj->render();
     $pdf->Output($this->title . '.pdf', 'D');
 }
 public function render()
 {
     if ($this->end && $this->end < $this->pdf->PageNo() || $this->start > $this->pdf->PageNo()) {
         return false;
     }
     $this->pdf->SetFont($this->font, $this->fontStyle, $this->fontSize);
     $fontColor = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->SetTextColor($fontColor['r'], $fontColor['g'], $fontColor['b']);
     if (!$this->left) {
         $this->left = $this->pdf->getX();
     }
     if (!$this->top) {
         $this->top = $this->pdf->getY();
     }
     $initial = $this->pdf->angle;
     $this->pdf->Rotate($this->rotation, $this->left, $this->top);
     $this->pdf->Text($this->left, $this->top, $this->content);
     $this->pdf->Rotate($initial);
 }
 /**
  * Draw a circle sector.
  *
  * @param integer $xc center abscis
  * @param integer $yc center ordonnate
  * @param integer $a begin angle (degree)
  * @param integer $b end angle (degree)
  * @param string $color fill color
  * @param string $style fill style [D(draw)|F(fill)|FD|DF]
  * @param boolean $cw rotate wise (true: clock wise, false: counter clock wise)
  * @param integer $o origine angle (0 to right, 90 to top, 180 to left, 270 to bottom)
  * @return void 
  */
 public static function sector($xc, $yc, $r, $a, $b, $color = '#ffffff', $style = 'FD', $cw = true, $o = 90)
 {
     $tab = Xml2Pdf::ConvertColor($color);
     $pdf = Pdf::singleton();
     $pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
     if ($cw) {
         $d = $b;
         $b = $o - $a;
         $a = $o - $d;
     } else {
         $b += $o;
         $a += $o;
     }
     $a = $a % 360 + 360;
     $b = $b % 360 + 360;
     if ($a > $b) {
         $b += 360;
     }
     $b = $b / 360 * 2 * M_PI;
     $a = $a / 360 * 2 * M_PI;
     $d = $b - $a;
     if ($d == 0) {
         $d = 2 * M_PI;
     }
     $k = $pdf->k;
     $hp = $pdf->h;
     if ($style == 'F') {
         $op = 'f';
     } elseif ($style == 'FD' or $style == 'DF') {
         $op = 'b';
     } else {
         $op = 's';
     }
     if (sin($d / 2)) {
         $MyArc = 4 / 3 * (1 - cos($d / 2)) / sin($d / 2) * $r;
     }
     //first put the center
     $pdf->_out(sprintf('%.2f %.2f m', $xc * $k, ($hp - $yc) * $k));
     //put the first point
     $pdf->_out(sprintf('%.2f %.2f l', ($xc + $r * cos($a)) * $k, ($hp - ($yc - $r * sin($a))) * $k));
     //draw the arc
     if ($d < M_PI / 2) {
         xml2pdf_graph_circle::arc($xc + $r * cos($a) + $MyArc * cos(M_PI / 2 + $a), $yc - $r * sin($a) - $MyArc * sin(M_PI / 2 + $a), $xc + $r * cos($b) + $MyArc * cos($b - M_PI / 2), $yc - $r * sin($b) - $MyArc * sin($b - M_PI / 2), $xc + $r * cos($b), $yc - $r * sin($b));
     } else {
         $b = $a + $d / 4;
         $MyArc = 4 / 3 * (1 - cos($d / 8)) / sin($d / 8) * $r;
         xml2pdf_graph_circle::arc($xc + $r * cos($a) + $MyArc * cos(M_PI / 2 + $a), $yc - $r * sin($a) - $MyArc * sin(M_PI / 2 + $a), $xc + $r * cos($b) + $MyArc * cos($b - M_PI / 2), $yc - $r * sin($b) - $MyArc * sin($b - M_PI / 2), $xc + $r * cos($b), $yc - $r * sin($b));
         $a = $b;
         $b = $a + $d / 4;
         xml2pdf_graph_circle::arc($xc + $r * cos($a) + $MyArc * cos(M_PI / 2 + $a), $yc - $r * sin($a) - $MyArc * sin(M_PI / 2 + $a), $xc + $r * cos($b) + $MyArc * cos($b - M_PI / 2), $yc - $r * sin($b) - $MyArc * sin($b - M_PI / 2), $xc + $r * cos($b), $yc - $r * sin($b));
         $a = $b;
         $b = $a + $d / 4;
         xml2pdf_graph_circle::arc($xc + $r * cos($a) + $MyArc * cos(M_PI / 2 + $a), $yc - $r * sin($a) - $MyArc * sin(M_PI / 2 + $a), $xc + $r * cos($b) + $MyArc * cos($b - M_PI / 2), $yc - $r * sin($b) - $MyArc * sin($b - M_PI / 2), $xc + $r * cos($b), $yc - $r * sin($b));
         $a = $b;
         $b = $a + $d / 4;
         xml2pdf_graph_circle::arc($xc + $r * cos($a) + $MyArc * cos(M_PI / 2 + $a), $yc - $r * sin($a) - $MyArc * sin(M_PI / 2 + $a), $xc + $r * cos($b) + $MyArc * cos($b - M_PI / 2), $yc - $r * sin($b) - $MyArc * sin($b - M_PI / 2), $xc + $r * cos($b), $yc - $r * sin($b));
     }
     //terminate drawing
     $pdf->_out($op);
 }
示例#16
0
文件: Template.php 项目: arhe/pwak
 /**
  * Crée et affiche un document pdf.
  *
  * Utilisation:
  * <code>
  * $smartyParams = array(
  *     'foo' => 'foosValue',
  *     'bar' => 'barsValue');
  * $outputOptions = array(
  *     'name' => 'myDocumentName',
  *     'dest' => 'I');
  * Template::pdf('path/to/the/template.xml',
  *     $smartyParams, $outputOptions);
  * </code>
  *
  * @param string $xmlTpl nom du template xml
  * @param array $params tableau de valeurs à passer au template
  * @param array $outputOpt options de sortie du pdf
  *      ('name'=>'docname', 'dest'=>'[I|D|F|S]')
  * @return void
  */
 public static function pdf($xmlTpl, $params = array(), $outputOpt = array())
 {
     if (!isset($outputOpt['name'])) {
         $outputOpt['name'] = 'doc.pdf';
     }
     if (!isset($outputOpt['dest'])) {
         $outputOpt['dest'] = 'I';
     }
     require_once 'xml2pdf/Xml2Pdf.php';
     $template = new Template();
     foreach ($params as $key => $value) {
         $template->assign($key, $value);
     }
     $xml = $template->fetch($xmlTpl);
     $xml2pdf = new Xml2Pdf($xml);
     $pdf = $xml2pdf->render();
     $pdf->Output($outputOpt['name'], $outputOpt['dest']);
 }
 /**
  * Render the paragraph or add it to the parent tag.
  * 
  * @return void
  */
 public function close()
 {
     if ($this->parent) {
         $this->parent->elements[] = $this;
         return;
     }
     // calc the paragraph left and top using : align, position, left and top
     if ($this->position == 'absolute') {
         $x = $this->left;
         $y = $this->top;
     } else {
         $pageWidth = 210 - $this->pdf->lMargin - $this->pdf->rMargin;
         if ($this->left) {
             $x = $this->pdf->GetX() + $this->left;
         } elseif ($this->align) {
             if ($this->align == 'L') {
                 $x = $this->pdf->lMargin;
             } elseif ($this->align == 'R') {
                 $x = $pageWidth - $this->width + $this->pdf->rMargin;
             } elseif ($this->align == 'C') {
                 $x = ($pageWidth - $this->width) / 2 + $this->pdf->lMargin;
             }
         } else {
             $x = $this->pdf->GetX();
         }
         if ($this->top) {
             $y = $this->pdf->GetY() + $this->top;
         } else {
             $y = $this->pdf->GetY();
         }
     }
     if (!$x) {
         $x = $this->pdf->lMargin;
     }
     if (!$y) {
         $y = $this->pdf->tMargin;
     }
     $this->pdf->SetXY($x, $y);
     // set the paragraph font, fill, border and draw params
     $borderColor = Xml2Pdf::convertColor($this->borderColor);
     $this->pdf->SetDrawColor($borderColor['r'], $borderColor['g'], $borderColor['b']);
     $fillColor = Xml2Pdf::convertColor($this->fillColor);
     $this->pdf->SetFillColor($fillColor['r'], $fillColor['g'], $fillColor['b']);
     $fontColor = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->setTextColor($fontColor['r'], $fontColor['g'], $fontColor['b']);
     $this->pdf->setFont($this->font, $this->fontStyle, $this->fontSize);
     // write the content
     $this->pdf->multicell($this->width, $this->lineHeight, $this->content, $this->border, $this->textAlign, $this->fill);
 }
 /**
  * Build the graph using appropriate plugin.
  *
  * Instantiate the plugin graph class to render the graph.
  *
  * @return boolean 
  */
 private function _drawGraph()
 {
     $clsName = Xml2Pdf::searchPlugin($this->type, 'graph');
     call_user_func(array($clsName, 'render'), $this);
     return true;
 }
示例#19
0
 /**
  * render the cell.
  *
  * @return void 
  */
 public function render()
 {
     // set colors
     $borderColor = Xml2Pdf::convertColor($this->borderColor);
     $this->pdf->SetDrawColor($borderColor["r"], $borderColor["g"], $borderColor["b"]);
     $fillColor = Xml2Pdf::convertColor($this->fillColor);
     $this->pdf->SetFillColor($fillColor["r"], $fillColor["g"], $fillColor["b"]);
     $fontColor = Xml2Pdf::convertColor($this->fontColor);
     $this->pdf->setTextColor($fontColor["r"], $fontColor["g"], $fontColor["b"]);
     $this->pdf->SetFont($this->font, $this->fontStyle, $this->fontSize);
     $x = $this->pdf->GetX();
     $y = $this->pdf->GetY();
     if ($this->fill || $this->border) {
         $mode = '';
         if ($this->fill) {
             $mode .= 'F';
         }
         if ($this->border) {
             $mode .= 'D';
         }
         $this->pdf->Rect($x, $y, $this->width, $this->height, $mode);
     }
     $this->pdf->MultiCell($this->width, $this->lineHeight, $this->content, 0, $this->textAlign, 0);
     //Put the position to the right of the cell
     $this->pdf->SetXY($x + $this->width, $y);
 }
 /**
  * Draw an horizontal bar graph.
  *
  * @param Object $graph object xml2pdf_tag_graph
  * @return void 
  */
 public static function render($graph)
 {
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $graph->setLegends();
     $XPage = $graph->pdf->GetX();
     $YPage = $graph->pdf->GetY();
     $marge = 2;
     $YDiag = $YPage + $marge;
     $hDiag = floor($graph->height - $marge * 2);
     $XDiag = $XPage + $marge * 2 + $graph->legendWidth;
     $lDiag = floor($graph->width - $marge * 3 - $graph->legendWidth);
     if ($graph->color == null) {
         $graph->color = Xml2Pdf::getColor();
     }
     if ($graph->maxValRepere == 0) {
         $graph->maxValRepere = max($graph->data);
     }
     $valIndRepere = ceil($graph->maxValRepere / $graph->nbIndRepere);
     $graph->maxValRepere = $valIndRepere * $graph->nbIndRepere;
     $lRepere = floor($lDiag / $graph->nbIndRepere);
     $lDiag = $lRepere * $graph->nbIndRepere;
     $unite = $lDiag / $graph->maxValRepere;
     $hBaton = floor($hDiag / ($graph->nbVal + 1));
     $hDiag = $hBaton * ($graph->nbVal + 1);
     $eBaton = floor($hBaton * 80 / 100);
     $graph->pdf->SetLineWidth(0.2);
     $graph->pdf->Rect($XDiag, $YDiag, $lDiag, $hDiag);
     //Echelles
     $tab = Xml2Pdf::ConvertColor('#dcdcdc');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     for ($i = 0; $i <= $graph->nbIndRepere; $i++) {
         $xpos = $XDiag + $lRepere * $i;
         if ($i > 0 && $i < $graph->nbIndRepere) {
             $graph->pdf->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
         }
         $val = $i * $valIndRepere;
         $xpos = $XDiag + $lRepere * $i - $graph->pdf->GetStringWidth($val) / 2;
         $ypos = $YDiag + $hDiag - $marge;
         $graph->pdf->Text($xpos, $ypos, $val);
     }
     $tab = Xml2Pdf::ConvertColor('#000000');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $tab = Xml2Pdf::ConvertColor($graph->color);
     $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
     $i = 0;
     foreach ($graph->data as $val) {
         //Barre
         $xval = $XDiag;
         $lval = (int) ($val * $unite);
         $yval = $YDiag + ($i + 1) * $hBaton - $eBaton / 2;
         $hval = $eBaton;
         $graph->pdf->Rect($xval, $yval, $lval, $hval, 'DF');
         //Légende
         $graph->pdf->SetXY(0, $yval);
         $graph->pdf->Cell($xval - $marge, $hval, $graph->legends[$i], 0, 0, 'R');
         $i++;
     }
 }
示例#21
0
 /**
  * Render the footer.
  *
  * @return boolean 
  */
 public function render()
 {
     if ($this->endPage && $this->endPage < $this->pdf->PageNo() || $this->startPage > $this->pdf->PageNo()) {
         return false;
     }
     foreach ($this->elements as $paragraph) {
         $content = null;
         $this->_resetFontValues();
         if (is_a($paragraph, 'xml2pdf_tag_numerotation')) {
             $content = sprintf($paragraph->content, $this->pdf->PageNo());
         }
         // initialize parametters
         $contentLength = $this->pdf->GetStringWidth($paragraph->content);
         $width = isset($paragraph->width) ? $paragraph->width : $contentLength + 20;
         $textalign = isset($paragraph->textAlign) ? $paragraph->textAlign : $this->textAlign;
         $align = isset($paragraph->align) ? $paragraph->align : $this->align;
         $lineHeight = isset($paragraph->lineHeight) ? $paragraph->lineHeight : $this->lineHeight;
         $border = isset($paragraph->border) ? $paragraph->border : $this->border;
         $borderColor = Xml2Pdf::convertColor(isset($paragraph->borderColor) ? $paragraph->borderColor : $this->borderColor);
         $fill = isset($paragraph->fill) ? $paragraph->fill : $this->fill;
         $fillColor = Xml2Pdf::convertColor(isset($paragraph->fillColor) ? $paragraph->fillColor : $this->fillColor);
         $font = isset($paragraph->font) ? $paragraph->font : $this->font;
         $fontSize = isset($paragraph->fontSize) ? $paragraph->fontSize : $this->fontSize;
         $fontStyle = isset($paragraph->fontStyle) ? $paragraph->fontStyle : $this->fontStyle;
         $fontColor = Xml2Pdf::convertColor(isset($paragraph->fontColor) ? $paragraph->fontColor : $this->fontColor);
         $textalign = isset($paragraph->textAlign) ? $paragraph->textAlign : $this->textAlign;
         $position = isset($paragraph->position) ? $paragraph->position : 'relative';
         $left = isset($paragraph->left) ? $paragraph->left : $this->left;
         $top = isset($paragraph->top) ? $paragraph->top : $this->top;
         //set colors
         $this->pdf->SetDrawColor($borderColor["r"], $borderColor["g"], $borderColor["b"]);
         $this->pdf->SetFillColor($fillColor["r"], $fillColor["g"], $fillColor["b"]);
         $this->pdf->setTextColor($fontColor["r"], $fontColor["g"], $fontColor["b"]);
         $this->pdf->SetFont($font, $fontStyle, $fontSize);
         //set position
         if ($position == "absolute") {
             $currentX = $left;
             $currentY = $this->pdf->bMargin - $top;
         } else {
             if ($align == "R") {
                 $currentX = $this->pdf->w - $this->pdf->rMargin - $contentLength - 3;
                 $currentY = $this->pdf->bMargin;
             } elseif ($align == "L") {
                 $currentX = $this->pdf->lMargin;
                 $currentY = $this->pdf->bMargin;
             } elseif ($align == "C") {
                 $currentX = ($this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin - $contentLength) / 2;
                 $currentY = $this->pdf->bMargin;
             } else {
                 $currentX = $this->pdf->GetX() + $left;
                 $currentY = $this->pdf->bMargin;
                 //$currentY = $this->pdf->GetY() + $top;
             }
         }
         $this->pdf->SetXY($currentX, -$currentY);
         // data
         if (empty($content)) {
             $content = $paragraph->content;
         }
         $this->pdf->MultiCell($width, $lineHeight, $content, $border, $textalign, $fill);
     }
     return true;
 }
示例#22
0
 /**
  * Parse the opening tags.
  *
  * Try to instantitate the tag's plugin class.
  *
  * @param object $parser parser xml
  * @param string $tag tag name
  * @param array $tagProperties tag's attributes
  * @return void
  */
 private function _parseOpeningTag($parser, $tag, $tagProperties)
 {
     if (isset($this->_pdf->styles[$tag])) {
         $this->_parseContent($parser, '<' . $tag . '>');
         return;
     }
     if ($this->_donotparse) {
         $tagToText = '<' . strtolower($tag);
         foreach ($tagProperties as $key => $value) {
             $tagToText .= ' ' . strtolower($key) . '="' . $value . '"';
         }
         $tagToText .= '/>';
         $this->_parseContent($parser, $tagToText);
         return;
     }
     $tagName = strtolower($tag);
     $clsName = Xml2Pdf::searchPlugin($tagName);
     try {
         $parent = array_pop($this->_tagStack);
         array_push($this->_tagStack, $parent);
         $this->_tagStack[] = new $clsName($tagProperties, $parent);
         if ($tag == 'LITERAL') {
             $this->_donotparse = true;
         }
     } catch (Exception $e) {
         $this->_tagStack[] = new $clsName($tagProperties);
     }
 }
示例#23
0
 private function generatePdf($content)
 {
     $obj = new Xml2Pdf($content);
     $pdf = $obj->render();
     $pdf->Output();
 }