public function testAdd() { $dictionaryObj = new InternalType\DictionaryObject(); $dictionaryObj->add(new InternalType\NameObject('Var1'), new InternalType\BooleanObject(false)); $dictionaryObj->add(new InternalType\NameObject('Var2'), new InternalType\NumericObject(100.426)); $dictionaryObj->add(new InternalType\NameObject('Var3'), new InternalType\NameObject('MyName')); $dictionaryObj->add(new InternalType\NameObject('Var4'), new InternalType\StringObject('some text')); $this->assertEquals($dictionaryObj->toString(), '<</Var1 false /Var2 100.426 /Var3 /MyName /Var4 (some text) >>'); }
/** * Read dictionary PDF object * Also reads trailing '>>' from a pdf stream * * @return \Zend\Pdf\InternalType\DictionaryObject * @throws \Zend\Pdf\Exception */ private function _readDictionary() { $dictionary = new InternalType\DictionaryObject(); while (strlen($nextLexeme = $this->readLexeme()) != 0) { if ($nextLexeme != '>>') { $nameStart = $this->offset - strlen($nextLexeme); $name = $this->readElement($nextLexeme); $value = $this->readElement(); if (!$name instanceof InternalType\NameObject) { throw new Pdf\Exception(sprintf('PDF file syntax error. Name object expected while dictionary reading. Offset - 0x%X.', $nameStart)); } $dictionary->add($name, $value); } else { return $dictionary; } } throw new Pdf\Exception(sprintf('PDF file syntax error. Unexpected end of file while dictionary reading. Offset - 0x%X. \'>>\' expected.', $this->offset)); }