示例#1
0
 private function generatePdf($content)
 {
     $obj = new Xml2Pdf($content);
     $pdf = $obj->render();
     $pdf->Output();
 }
示例#2
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');
 }
示例#3
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']);
 }