/** * Reads the Pascal string from the binary file at the current byte offset. * * The length of the Pascal string is determined by reading the length bytes * which preceed the character data. You must supply the desired resulting * character set. * * Advances the offset by the number of bytes read. Throws an exception if * an error occurs. * * @param string $characterSet (optional) Desired resulting character set. * You may use any character set supported by {@link iconv()}. If omitted, * uses 'current locale'. * @param integer $lengthBytes (optional) Number of bytes that make up the * length. Default is 1. * @return string * @throws Zend_Pdf_Exception */ public function readStringPascal($characterSet = '', $lengthBytes = 1) { $byteCount = $this->readUInt($lengthBytes); if ($byteCount == 0) { return ''; } $bytes = $this->_dataSource->readBytes($byteCount); if ($characterSet == 'ASCII') { return $bytes; } return iconv('ASCII', $characterSet, $bytes); }
/** * Seeks the file read position to the specified byte offset. * * Throws an exception if the file pointer cannot be moved or if it is * moved beyond EOF (end of file). * * @param integer $offset Destination byte offset. * @throws Zend_Pdf_Exception */ public function moveToOffset($offset) { if ($this->_offset == $offset) { return; // Not moving; do nothing. } parent::moveToOffset($offset); $result = @fseek($this->_fileResource, $offset, SEEK_SET); if ($result !== 0) { //require_once 'Zend/Pdf/Exception.php'; throw new Zend_Pdf_Exception('Error while setting new file position', Zend_Pdf_Exception::CANT_SET_FILE_POSITION); } if (feof($this->_fileResource)) { //require_once 'Zend/Pdf/Exception.php'; throw new Zend_Pdf_Exception('Moved beyond the end of the file', Zend_Pdf_Exception::MOVE_BEYOND_END_OF_FILE); } }