Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Zend_Pdf_FileParser Class Reference

Public Member Functions

 screen ()
 Performs a cursory check to verify that the binary file is in the expected format.
 
 parse ()
 Reads and parses the complete binary file.
 
 __construct (Zend_Pdf_FileParserDataSource $dataSource)
 Object constructor.
 
 __destruct ()
 Object destructor.
 
 isScreened ()
 Returns true if the file has passed a cursory validation check.
 
 isParsed ()
 Returns true if the file has been successfully parsed.
 
 getDataSource ()
 Returns the data source object representing the file being parsed.
 
 moveToOffset ($offset)
 Convenience wrapper for the data source object's moveToOffset() method.
 
 getOffset ()
 
 getSize ()
 
 readBytes ($byteCount)
 Convenience wrapper for the data source object's readBytes() method.
 
 skipBytes ($byteCount)
 Convenience wrapper for the data source object's skipBytes() method.
 
 readInt ($size, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
 Reads the signed integer value from the binary file at the current byte offset.
 
 readUInt ($size, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
 Reads the unsigned integer value from the binary file at the current byte offset.
 
 isBitSet ($bit, $bitField)
 Returns true if the specified bit is set in the integer bitfield.
 
 readFixed ($mantissaBits, $fractionBits, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
 Reads the signed fixed-point number from the binary file at the current byte offset.
 
 readStringUTF16 ($byteCount, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN, $characterSet= '')
 Reads the Unicode UTF-16-encoded string from the binary file at the current byte offset.
 
 readStringMacRoman ($byteCount, $characterSet= '')
 Reads the Mac Roman-encoded string from the binary file at the current byte offset.
 
 readStringPascal ($characterSet= '', $lengthBytes=1)
 Reads the Pascal string from the binary file at the current byte offset.
 

Public Attributes

const BYTE_ORDER_LITTLE_ENDIAN = 0
 Little-endian byte order (0x04 0x03 0x02 0x01).
 
const BYTE_ORDER_BIG_ENDIAN = 1
 Big-endian byte order (0x01 0x02 0x03 0x04).
 

Protected Attributes

 $_isScreened = false
 
 $_isParsed = false
 
 $_dataSource = null
 

Constructor & Destructor Documentation

__construct ( Zend_Pdf_FileParserDataSource  $dataSource)

Object constructor.

Verifies that the data source has been properly initialized.

Parameters
Zend_Pdf_FileParserDataSource$dataSource
Exceptions
Zend_Pdf_Exception
__destruct ( )

Object destructor.

Discards the data source object.

Member Function Documentation

getDataSource ( )

Returns the data source object representing the file being parsed.

Returns
Zend_Pdf_FileParserDataSource
getOffset ( )
getSize ( )
isBitSet (   $bit,
  $bitField 
)

Returns true if the specified bit is set in the integer bitfield.

Parameters
integer$bitBit number to test (i.e. - 0-31)
integer$bitField
Returns
boolean
isParsed ( )

Returns true if the file has been successfully parsed.

Returns
boolean
isScreened ( )

Returns true if the file has passed a cursory validation check.

Returns
boolean
moveToOffset (   $offset)

Convenience wrapper for the data source object's moveToOffset() method.

Parameters
integer$offsetDestination byte offset.
Exceptions
Zend_Pdf_Exception
parse ( )
abstract

Reads and parses the complete binary file.

Must set $this->_isParsed to true if successful.

Exceptions
Zend_Pdf_Exception
readBytes (   $byteCount)

Convenience wrapper for the data source object's readBytes() method.

Parameters
integer$byteCountNumber of bytes to read.
Returns
string
Exceptions
Zend_Pdf_Exception
readFixed (   $mantissaBits,
  $fractionBits,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN 
)

Reads the signed fixed-point number from the binary file at the current byte offset.

Common fixed-point sizes are 2.14 and 16.16.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
integer$mantissaBitsNumber of bits in the mantissa
integer$fractionBitsNumber of bits in the fraction
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
Returns
float
Exceptions
Zend_Pdf_Exception
readInt (   $size,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN 
)

Reads the signed integer value from the binary file at the current byte offset.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
integer$sizeSize of integer in bytes: 1-4
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
Returns
integer
Exceptions
Zend_Pdf_Exception
readStringMacRoman (   $byteCount,
  $characterSet = '' 
)

Reads the Mac Roman-encoded string from the binary file at the current byte offset.

You must supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
integer$byteCountNumber of bytes (characters) to return.
string$characterSet(optional) Desired resulting character set. You may use any character set supported by iconv(). If omitted, uses 'current locale'.
Returns
string
Exceptions
Zend_Pdf_Exception
readStringPascal (   $characterSet = '',
  $lengthBytes = 1 
)

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.

Parameters
string$characterSet(optional) Desired resulting character set. You may use any character set supported by iconv(). If omitted, uses 'current locale'.
integer$lengthBytes(optional) Number of bytes that make up the length. Default is 1.
Returns
string
Exceptions
Zend_Pdf_Exception
readStringUTF16 (   $byteCount,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN,
  $characterSet = '' 
)

Reads the Unicode UTF-16-encoded string from the binary file at the current byte offset.

The byte order of the UTF-16 string must be specified. You must also supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Todo:

Consider changing $byteCount to a character count. They are not always equivalent (in the case of surrogates).

Make $byteOrder optional if there is a byte-order mark (BOM) in the string being extracted.

Parameters
integer$byteCountNumber of bytes (characters * 2) to return.
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
string$characterSet(optional) Desired resulting character set. You may use any character set supported by iconv(). If omitted, uses 'current locale'.
Returns
string
Exceptions
Zend_Pdf_Exception
readUInt (   $size,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN 
)

Reads the unsigned integer value from the binary file at the current byte offset.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

NOTE: If you ask for a 4-byte unsigned integer on a 32-bit machine, the resulting value WILL BE SIGNED because PHP uses signed integers internally for everything. To guarantee portability, be sure to use bitwise operators operators on large unsigned integers!

Parameters
integer$sizeSize of integer in bytes: 1-4
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
Returns
integer
Exceptions
Zend_Pdf_Exception
screen ( )
abstract

Performs a cursory check to verify that the binary file is in the expected format.

Intended to quickly weed out obviously bogus files.

Must set $this->_isScreened to true if successful.

Exceptions
Zend_Pdf_Exception
skipBytes (   $byteCount)

Convenience wrapper for the data source object's skipBytes() method.

Parameters
integer$byteCountNumber of bytes to skip.
Exceptions
Zend_Pdf_Exception

Member Data Documentation

$_dataSource = null
protected
$_isParsed = false
protected
$_isScreened = false
protected
const BYTE_ORDER_BIG_ENDIAN = 1

Big-endian byte order (0x01 0x02 0x03 0x04).

const BYTE_ORDER_LITTLE_ENDIAN = 0

Little-endian byte order (0x04 0x03 0x02 0x01).