/** * @return array */ public function getDetails($deep = true) { $details = array(); $details['BaseEncoding'] = $this->has('BaseEncoding') ? (string) $this->get('BaseEncoding') : 'Ansi'; $details['Differences'] = $this->has('Differences') ? (string) $this->get('Differences') : ''; $details += parent::getDetails($deep); return $details; }
/** * @param Page * * @return string */ public function getText(Page $page = null) { $header = new Header(array(), $this->document); $contents = new Object($this->document, $header, $this->content); return $contents->getText($this); }
/** * @param string $id * @param array $structure * @param Document $document */ protected function parseObject($id, $structure, $document) { $header = new Header(array(), $document); $content = ''; foreach ($structure as $position => $part) { switch ($part[0]) { case '[': $elements = array(); foreach ($part[1] as $sub_element) { $sub_type = $sub_element[0]; $sub_value = $sub_element[1]; $elements[] = $this->parseHeaderElement($sub_type, $sub_value, $document); } $header = new Header($elements, $document); break; case '<<': $header = $this->parseHeader($part[1], $document); break; case 'stream': $content = isset($part[3][0]) ? $part[3][0] : $part[1]; if ($header->get('Type')->equals('ObjStm')) { $match = array(); // Split xrefs and contents. preg_match('/^((\\d+\\s+\\d+\\s*)*)(.*)$/s', $content, $match); $content = $match[3]; // Extract xrefs. $xrefs = preg_split('/(\\d+\\s+\\d+\\s*)/s', $match[1], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $table = array(); foreach ($xrefs as $xref) { list($id, $position) = explode(' ', trim($xref)); $table[$position] = $id; } ksort($table); $ids = array_values($table); $positions = array_keys($table); foreach ($positions as $index => $position) { $id = $ids[$index] . '_0'; $next_position = isset($positions[$index + 1]) ? $positions[$index + 1] : strlen($content); $sub_content = substr($content, $position, $next_position - $position); $sub_header = Header::parse($sub_content, $document); $object = Object::factory($document, $sub_header, ''); $this->objects[$id] = $object; } // It is not necessary to store this content. $content = ''; return; } break; default: if ($part != 'null') { $element = $this->parseHeaderElement($part[0], $part[1], $document); if ($element) { $header = new Header(array($element), $document); } } break; } } if (!isset($this->objects[$id])) { $this->objects[$id] = Object::factory($document, $header, $content); } }
/** * @param Page * * @return string */ public function getText(Page $page = null) { if ($contents = $this->get('Contents')) { if ($contents instanceof ElementMissing) { return ''; } elseif ($contents instanceof Object) { $elements = $contents->getHeader()->getElements(); if (is_numeric(key($elements))) { $new_content = ''; foreach ($elements as $element) { if ($element instanceof ElementXRef) { $new_content .= $element->getObject()->getContent(); } else { $new_content .= $element->getContent(); } } $header = new Header(array(), $this->document); $contents = new Object($this->document, $header, $new_content); } } elseif ($contents instanceof ElementArray) { // Create a virtual global content. $new_content = ''; foreach ($contents->getContent() as $content) { $new_content .= $content->getContent() . "\n"; } $header = new Header(array(), $this->document); $contents = new Object($this->document, $header, $new_content); } return $contents->getText($this); } return ''; }
/** * @param Page * * @return string */ public function getText(Page $page = null) { $contents = $this->get('Contents'); if ($contents) { if ($contents instanceof ElementArray) { // Create a virtual global content. $new_content = ''; foreach ($contents->getContent() as $content) { $new_content .= $content->getContent() . "\n"; } $header = new Header(array(), $this->document); $contents = new Object($this->document, $header, $new_content); return $contents->getText($this); } elseif (!$contents instanceof ElementMissing) { return $contents->getText($this); } } return ''; }