API Documentation

Pdf/FileParser.php

Classes 
category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Pdf
subpackage
FileParser
version
$Id: FileParser.php 20096 2010-01-06 02:05:09Z bkarwin $
Classes
Zend_Pdf_FileParser

Description

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

Zend_Pdf_FileParser

copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Pdf
subpackage
FileParser
Constants
BYTE_ORDER_LITTLE_ENDIAN
BYTE_ORDER_BIG_ENDIAN
Properties
$_isScreened
$_isParsed
$_dataSource
Methods
screen
parse
__construct
__destruct
isScreened
isParsed
getDataSource
moveToOffset
getOffset
getSize
readBytes
skipBytes
readInt
readUInt
isBitSet
readFixed
readStringUTF16
readStringMacRoman
readStringPascal

Description

Abstract utility class for parsing binary files.

Provides a library of methods to quickly navigate and extract various data types (signed and unsigned integers, floating- and fixed-point numbers, strings, etc.) from the file.

File access is managed via a {@link Zend_Pdf_FileParserDataSource} object. This allows the same parser code to work with many different data sources: in-memory objects, filesystem files, etc.

Constants

BYTE_ORDER_LITTLE_ENDIAN

 BYTE_ORDER_LITTLE_ENDIAN = '0'

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

Details

value
0

BYTE_ORDER_BIG_ENDIAN

 BYTE_ORDER_BIG_ENDIAN = '1'

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

Details

value
1

Properties

$_dataSource

Zend_Pdf_FileParserDataSource $_dataSource = 'null'

Object representing the data source to be parsed.

Details

$_dataSource
Zend_Pdf_FileParserDataSource
visibility
protected
default
null
final
false
static
false

$_isParsed

boolean $_isParsed = 'false'

Flag indicating that the file has been sucessfully parsed.

Details

$_isParsed
boolean
visibility
protected
default
false
final
false
static
false

$_isScreened

boolean $_isScreened = 'false'

Flag indicating that the file has passed a cursory validation check.

Details

$_isScreened
boolean
visibility
protected
default
false
final
false
static
false

Methods

__construct

__construct( Zend_Pdf_FileParserDataSource $dataSource ) :

Object constructor.

Verifies that the data source has been properly initialized.

Arguments
$dataSource
Zend_Pdf_FileParserDataSource
Details
visibility
public
final
false
static
false
throws

__destruct

__destruct( ) :

Object destructor.

Discards the data source object.

Details
visibility
public
final
false
static
false

getDataSource

getDataSource( ) : Zend_Pdf_FileParserDataSource

Returns the data source object representing the file being parsed.

Details
visibility
public
final
false
static
false

getOffset

getOffset( ) :
Details
visibility
public
final
false
static
false

getSize

getSize( ) :
Details
visibility
public
final
false
static
false

isBitSet

isBitSet( integer $bit, integer $bitField ) : boolean

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

Arguments
$bit
integer
Bit number to test (i.e. - 0-31)
$bitField
integer
Output
boolean
Details
visibility
public
final
false
static
false

isParsed

isParsed( ) : boolean

Returns true if the file has been successfully parsed.

Output
boolean
Details
visibility
public
final
false
static
false

isScreened

isScreened( ) : boolean

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

Output
boolean
Details
visibility
public
final
false
static
false

moveToOffset

moveToOffset( integer $offset ) :

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

Arguments
$offset
integer
Destination byte offset.
Details
visibility
public
final
false
static
false
throws

parse

parse( ) :

Reads and parses the complete binary file.

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

Details
visibility
public
final
false
static
false
throws

readBytes

readBytes( integer $byteCount ) : string

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

Arguments
$byteCount
integer
Number of bytes to read.
Output
string
Details
visibility
public
final
false
static
false
throws

readFixed

readFixed( integer $mantissaBits, integer $fractionBits, integer $byteOrder = Zend_Pdf_FileParser ) : float

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.

Arguments
$mantissaBits
integer
Number of bits in the mantissa
$fractionBits
integer
Number of bits in the fraction
$byteOrder
integer
(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.
Output
float
Details
visibility
public
final
false
static
false
throws

readInt

readInt( integer $size, integer $byteOrder = Zend_Pdf_FileParser ) : integer

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.

Arguments
$size
integer
Size of integer in bytes: 1-4
$byteOrder
integer
(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.
Output
integer
Details
visibility
public
final
false
static
false
throws

readStringMacRoman

readStringMacRoman( integer $byteCount, string $characterSet ) : string

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.

Arguments
$byteCount
integer
Number of bytes (characters) to return.
$characterSet
string
(optional) Desired resulting character set. You may use any character set supported by {@link iconv()}. If omitted, uses 'current locale'.
Output
string
Details
visibility
public
final
false
static
false
throws

readStringPascal

readStringPascal( string $characterSet, integer $lengthBytes = 1 ) : string

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.

Arguments
$characterSet
string
(optional) Desired resulting character set. You may use any character set supported by {@link iconv()}. If omitted, uses 'current locale'.
$lengthBytes
integer
(optional) Number of bytes that make up the length. Default is 1.
Output
string
Details
visibility
public
final
false
static
false
throws

readStringUTF16

readStringUTF16( integer $byteCount, integer $byteOrder = Zend_Pdf_FileParser, string $characterSet ) : string

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.

Arguments
$byteCount
integer
Number of bytes (characters * 2) to return.
$byteOrder
integer
(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.
$characterSet
string
(optional) Desired resulting character set. You may use any character set supported by {@link iconv()}. If omitted, uses 'current locale'.
Output
string
Details
visibility
public
final
false
static
false
throws
todo
Consider changing $byteCount to a character count. They are not always equivalent (in the case of surrogates).
todo
Make $byteOrder optional if there is a byte-order mark (BOM) in the string being extracted.

readUInt

readUInt( integer $size, integer $byteOrder = Zend_Pdf_FileParser ) : integer

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!

Arguments
$size
integer
Size of integer in bytes: 1-4
$byteOrder
integer
(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.
Output
integer
Details
visibility
public
final
false
static
false
throws

screen

screen( ) :

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.

Details
visibility
public
final
false
static
false
throws

skipBytes

skipBytes( integer $byteCount ) :

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

Arguments
$byteCount
integer
Number of bytes to skip.
Details
visibility
public
final
false
static
false
throws
Documentation was generated by DocBlox.