Example #1
0
 protected function _writeValue(&$value)
 {
     if (is_subclass_of($this, '\\TCPDF')) {
         parent::_prepareValue($value);
     }
     switch ($value[0]) {
         case \fpdi\pdf_parser::TYPE_TOKEN:
             $this->_straightOut($value[1] . ' ');
             break;
         case \fpdi\pdf_parser::TYPE_NUMERIC:
         case \fpdi\pdf_parser::TYPE_REAL:
             if (is_float($value[1]) && $value[1] != 0) {
                 $this->_straightOut(rtrim(rtrim(sprintf('%F', $value[1]), '0'), '.') . ' ');
             } else {
                 $this->_straightOut($value[1] . ' ');
             }
             break;
         case \fpdi\pdf_parser::TYPE_ARRAY:
             $this->_straightOut('[');
             for ($i = 0; $i < count($value[1]); $i++) {
                 $this->_writeValue($value[1][$i]);
             }
             $this->_out(']');
             break;
         case \fpdi\pdf_parser::TYPE_DICTIONARY:
             $this->_straightOut('<<');
             reset($value[1]);
             while (list($k, $v) = each($value[1])) {
                 $this->_straightOut($k . ' ');
                 $this->_writeValue($v);
             }
             $this->_straightOut('>>');
             break;
         case \fpdi\pdf_parser::TYPE_OBJREF:
             $cpfn =& $this->currentParser->filename;
             if (!isset($this->_doneObjStack[$cpfn][$value[1]])) {
                 $this->_newobj(false, true);
                 $this->_objStack[$cpfn][$value[1]] = array($this->n, $value);
                 $this->_doneObjStack[$cpfn][$value[1]] = array($this->n, $value);
             }
             $objId = $this->_doneObjStack[$cpfn][$value[1]][0];
             $this->_out($objId . ' 0 R');
             break;
         case \fpdi\pdf_parser::TYPE_STRING:
             $this->_straightOut('(' . $value[1] . ')');
             break;
         case \fpdi\pdf_parser::TYPE_STREAM:
             $this->_writeValue($value[1]);
             $this->_out('stream');
             $this->_out($value[2][1]);
             $this->_straightOut('endstream');
             break;
         case \fpdi\pdf_parser::TYPE_HEX:
             $this->_straightOut('<' . $value[1] . '>');
             break;
         case \fpdi\pdf_parser::TYPE_BOOLEAN:
             $this->_straightOut($value[1] ? 'true ' : 'false ');
             break;
         case \fpdi\pdf_parser::TYPE_NULL:
             $this->_straightOut('null ');
             break;
     }
 }
Example #2
0
 /**
  * Writes a PDF value to the resulting document.
  *
  * Needed to rebuild the source document
  *
  * @param mixed $value A PDF-Value. Structure of values see cases in this method
  */
 protected function _writeValue(&$value)
 {
     if (is_subclass_of($this, 'TCPDF')) {
         parent::_prepareValue($value);
     }
     switch ($value[0]) {
         case pdf_parser::TYPE_TOKEN:
             $this->_straightOut($value[1] . ' ');
             break;
         case pdf_parser::TYPE_NUMERIC:
         case pdf_parser::TYPE_REAL:
             if (is_float($value[1]) && $value[1] != 0) {
                 $this->_straightOut(rtrim(rtrim(sprintf('%F', $value[1]), '0'), '.') . ' ');
             } else {
                 $this->_straightOut($value[1] . ' ');
             }
             break;
         case pdf_parser::TYPE_ARRAY:
             // An array. Output the proper
             // structure and move on.
             $this->_straightOut('[');
             for ($i = 0; $i < count($value[1]); $i++) {
                 $this->_writeValue($value[1][$i]);
             }
             $this->_out(']');
             break;
         case pdf_parser::TYPE_DICTIONARY:
             // A dictionary.
             $this->_straightOut('<<');
             reset($value[1]);
             while (list($k, $v) = each($value[1])) {
                 $this->_straightOut($k . ' ');
                 $this->_writeValue($v);
             }
             $this->_straightOut('>>');
             break;
         case pdf_parser::TYPE_OBJREF:
             // An indirect object reference
             // Fill the object stack if needed
             $cpfn =& $this->currentParser->filename;
             if (!isset($this->_doneObjStack[$cpfn][$value[1]])) {
                 $this->_newobj(false, true);
                 $this->_objStack[$cpfn][$value[1]] = array($this->n, $value);
                 $this->_doneObjStack[$cpfn][$value[1]] = array($this->n, $value);
             }
             $objId = $this->_doneObjStack[$cpfn][$value[1]][0];
             $this->_out($objId . ' 0 R');
             break;
         case pdf_parser::TYPE_STRING:
             // A string.
             $this->_straightOut('(' . $value[1] . ')');
             break;
         case pdf_parser::TYPE_STREAM:
             // A stream. First, output the
             // stream dictionary, then the
             // stream data itself.
             $this->_writeValue($value[1]);
             $this->_out('stream');
             $this->_out($value[2][1]);
             $this->_straightOut("endstream");
             break;
         case pdf_parser::TYPE_HEX:
             $this->_straightOut('<' . $value[1] . '>');
             break;
         case pdf_parser::TYPE_BOOLEAN:
             $this->_straightOut($value[1] ? 'true ' : 'false ');
             break;
         case pdf_parser::TYPE_NULL:
             // The null object.
             $this->_straightOut('null ');
             break;
     }
 }