PoDoFo 0.9.6
PoDoFo::PdfObject Class Reference

#include <PdfObject.h>

Inheritance diagram for PoDoFo::PdfObject:
PoDoFo::PdfVariant PoDoFo::PdfParserObject PoDoFo::PdfXRefStreamParserObject

Public Member Functions

 PdfObject ()
 PdfObject (const PdfReference &rRef, const char *pszType)
 PdfObject (const PdfReference &rRef, const PdfVariant &rVariant)
 PdfObject (const PdfVariant &var)
 PdfObject (bool b)
 PdfObject (pdf_int64 l)
 PdfObject (double d)
 PdfObject (const PdfString &rsString)
 PdfObject (const PdfName &rName)
 PdfObject (const PdfReference &rRef)
 PdfObject (const PdfArray &tList)
 PdfObject (const PdfDictionary &rDict)
 PdfObject (const PdfObject &rhs)
PdfObjectGetIndirectKey (const PdfName &key) const
PdfObjectMustGetIndirectKey (const PdfName &key) const
void WriteObject (PdfOutputDevice *pDevice, EPdfWriteMode eWriteMode, PdfEncrypt *pEncrypt, const PdfName &keyStop=PdfName::KeyNull) const
pdf_long GetObjectLength (EPdfWriteMode eWriteMode)
const PdfReferenceReference () const
PdfStreamGetStream ()
const PdfStreamGetStream () const
bool HasStream () const
PODOFO_NOTHROW bool operator< (const PdfObject &rhs) const
PODOFO_NOTHROW bool operator== (const PdfObject &rhs) const
PdfVecObjects * GetOwner () const
const PdfObjectoperator= (const PdfObject &rhs)
void FlateCompressStream ()
pdf_long GetByteOffset (const char *pszKey, EPdfWriteMode eWriteMode)
void DelayedStreamLoad () const
Public Member Functions inherited from PoDoFo::PdfVariant
 PdfVariant ()
 PdfVariant (bool b)
 PdfVariant (pdf_int64 l)
 PdfVariant (double d)
 PdfVariant (const PdfString &rsString)
 PdfVariant (const PdfName &rName)
 PdfVariant (const PdfReference &rRef)
 PdfVariant (const PdfArray &tList)
 PdfVariant (const PdfDictionary &rDict)
 PdfVariant (const PdfData &rData)
 PdfVariant (const PdfVariant &rhs)
bool IsEmpty () const
void Clear ()
EPdfDataType GetDataType () const
const char * GetDataTypeString () const
bool IsBool () const
bool IsNumber () const
bool IsReal () const
bool IsString () const
bool IsHexString () const
bool IsName () const
bool IsArray () const
bool IsDictionary () const
bool IsRawData () const
bool IsNull () const
bool IsReference () const
void Write (PdfOutputDevice *pDevice, EPdfWriteMode eWriteMode, const PdfEncrypt *pEncrypt=NULL) const
virtual void Write (PdfOutputDevice *pDevice, EPdfWriteMode eWriteMode, const PdfEncrypt *pEncrypt, const PdfName &keyStop) const
void ToString (std::string &rsData, EPdfWriteMode eWriteMode=ePdfWriteMode_Clean) const
void SetBool (bool b)
bool GetBool () const
void SetNumber (long l)
pdf_int64 GetNumber () const
void SetReal (double d)
double GetReal () const
void SetString (const PdfString &str)
const PdfStringGetString () const
const PdfNameGetName () const
const PdfArray & GetArray () const
PdfArray & GetArray ()
const PdfDictionary & GetDictionary () const
PdfDictionary & GetDictionary ()
const PdfReferenceGetReference () const
const PdfDataGetRawData () const
PdfDataGetRawData ()
const PdfVariantoperator= (const PdfVariant &rhs)
bool operator== (const PdfVariant &rhs) const
bool operator!= (const PdfVariant &rhs) const
bool IsDirty () const
void SetImmutable (bool bImmutable)
bool GetImmutable () const

Protected Member Functions

void EnableDelayedStreamLoading ()
virtual void DelayedStreamLoadImpl ()
PdfStreamGetStream_NoDL ()
virtual void AfterDelayedLoad (EPdfDataType eDataType)
void SetVariantOwner (EPdfDataType eDataType)
Protected Member Functions inherited from PoDoFo::PdfVariant
void AssertMutable () const
void SetDirty (bool bDirty)
void DelayedLoad () const
void EnableDelayedLoading ()
PODOFO_NOTHROW bool DelayedLoadDone () const
const PdfDictionary & GetDictionary_NoDL () const
PdfDictionary & GetDictionary_NoDL ()
const PdfArray & GetArray_NoDL () const
PdfArray & GetArray_NoDL ()

Detailed Description

This class represents a PDF indirect Object in memory

It is possible to manipulate the stream which can be appended to the object (if the object is of underlying type dictionary). A PdfObject is uniquely identified by an object number and a generation number which has to be passed to the constructor.

The object can be written to a file easily using the WriteObject() function.

See also
WriteObject()

Constructor & Destructor Documentation

◆ PdfObject() [1/13]

PoDoFo::PdfObject::PdfObject ( )

Create a PDF object with object and generation number -1 and the value of being an empty PdfDictionary.

◆ PdfObject() [2/13]

PoDoFo::PdfObject::PdfObject ( const PdfReference & rRef,
const char * pszType )

Construct a new PDF object of type PdfDictionary.

Parameters
rRefreference of this object
pszTypeif this parameter is not null a key "/Type" will be added to the dictionary with the parameter's value.

◆ PdfObject() [3/13]

PoDoFo::PdfObject::PdfObject ( const PdfReference & rRef,
const PdfVariant & rVariant )

Construct a new PDF object.

Parameters
rRefreference of this object
rVariantthe value of the PdfObject (which is copied)

◆ PdfObject() [4/13]

PoDoFo::PdfObject::PdfObject ( const PdfVariant & var)

Create a PDF object with object and generation number -1 and the value of the passed variant.

Parameters
varthe value of the object

◆ PdfObject() [5/13]

PoDoFo::PdfObject::PdfObject ( bool b)

Construct a PdfObject with object and generation number -1 and a bool as value.

Parameters
bthe boolean value of this PdfObject

◆ PdfObject() [6/13]

PoDoFo::PdfObject::PdfObject ( pdf_int64 l)

Construct a PdfObject with object and generation number -1 and a pdf_int64 as value.

Parameters
lthe pdf_int64 value of this PdfObject

◆ PdfObject() [7/13]

PoDoFo::PdfObject::PdfObject ( double d)

Construct a PdfObject with object and generation number -1 and a double as value.

Parameters
dthe double value of this PdfObject

◆ PdfObject() [8/13]

PoDoFo::PdfObject::PdfObject ( const PdfString & rsString)

Construct a PdfObject with object and generation number -1 and a PdfString as value.

Parameters
rsStringthe string value of this PdfObject

◆ PdfObject() [9/13]

PoDoFo::PdfObject::PdfObject ( const PdfName & rName)

Construct a PdfObject with object and generation number -1 and a PdfName as value.

Parameters
rNamethe value of this PdfObject

◆ PdfObject() [10/13]

PoDoFo::PdfObject::PdfObject ( const PdfReference & rRef)

Construct a PdfObject with object and generation number -1 and a PdfReference as value.

Parameters
rRefthe value of the this PdfObject

◆ PdfObject() [11/13]

PoDoFo::PdfObject::PdfObject ( const PdfArray & tList)

Construct a PdfObject with object and generation number -1 and a PdfArray as value.

Parameters
tListthe value of the this PdfObject

◆ PdfObject() [12/13]

PoDoFo::PdfObject::PdfObject ( const PdfDictionary & rDict)

Construct a PdfObject with object and generation number -1 and a PdfDictionary as value.

Parameters
rDictthe value of the this PdfObject

◆ PdfObject() [13/13]

PoDoFo::PdfObject::PdfObject ( const PdfObject & rhs)

Creates a copy of an existing PdfObject. All associated objects and streams will be copied along with the PdfObject.

Parameters
rhsPdfObject to clone

Member Function Documentation

◆ AfterDelayedLoad()

void PoDoFo::PdfObject::AfterDelayedLoad ( EPdfDataType eDataType)
protectedvirtual

Load all data of the object if delayed loading is enabled.

Never call this method directly; use DelayedLoad() instead.

You should override this to control deferred loading in your subclass. Note that this method should not load any associated streams, just the base object.

The default implementation throws. It should never be called, since objects that do not support delayed loading should not enable it.

While this method is not `const' it may be called from a const context, so be careful what you mess with. */ inline virtual void DelayedLoadImpl();

/** Called after delayed load

Parameters
eDataTypeDetected data type

Reimplemented from PoDoFo::PdfVariant.

◆ DelayedStreamLoad()

void PoDoFo::PdfObject::DelayedStreamLoad ( ) const
inline

Dynamically load this object and any associated stream from a PDF file by calling the virtual method DelayedStreamLoadImpl if the stream is not already loaded. Will call DelayedLoad() first if it is required.

Call graph:

DelayedStreamLoad ---> DelayedLoad() --> DelayedLoadImpl() | --> DelayedStreamLoadImpl()

For objects created in memory completely, this function does nothing.

◆ DelayedStreamLoadImpl()

void PoDoFo::PdfObject::DelayedStreamLoadImpl ( )
inlineprotectedvirtual

Load the stream of the object if it has one and if delayed loading is enabled.

You should override this to control deferred stream loading in your subclass.

Never call this method directly; use DelayedStreamLoad() instead.

Reimplemented in PoDoFo::PdfParserObject.

◆ EnableDelayedStreamLoading()

void PoDoFo::PdfObject::EnableDelayedStreamLoading ( )
inlineprotected

Flag any stream associated with the object as incompletely loaded, so that DelayedStreamLoad() will be called when needed.

All constructors initialize a PdfObject with delayed loading of streams disabled. If you want delayed loading of streams you must ask for it. If you do so, call this method early in your ctor and be sure to override DelayedStreamLoadImpl().

Note that it is quite possible to have a PdfObject that requires a delayed-load of its stream but does an immediate load of the PdfVariant base. If you want to delay loading of that too, make sure to call EnableDelayedLoading().

◆ FlateCompressStream()

void PoDoFo::PdfObject::FlateCompressStream ( )

This function compresses any currently set stream using the FlateDecode algorithm. JPEG compressed streams will not be compressed again using this function. Entries to the filter dictionary will be added if necessary.

◆ GetByteOffset()

pdf_long PoDoFo::PdfObject::GetByteOffset ( const char * pszKey,
EPdfWriteMode eWriteMode )

Calculate the byte offset of the key pszKey from the start of the object if the object was written to disk at the moment of calling this function.

This function is very calculation intensive!

Parameters
pszKeykey to calculate the byte offset of
eWriteModeadditional options for writing the PDF
Returns
the offset of the key

◆ GetIndirectKey()

PdfObject * PoDoFo::PdfObject::GetIndirectKey ( const PdfName & key) const

Get the key's value out of the dictionary. If the key is a reference, the reference is resolved and the object pointed to by the reference is returned.

Parameters
keylook for the key named key in the dictionary
Returns
the found value or NULL if the value is not in the dictionary or if this object is no dictionary

◆ GetObjectLength()

pdf_long PoDoFo::PdfObject::GetObjectLength ( EPdfWriteMode eWriteMode)

Get the length of the object in bytes if it was written to disk now.

Parameters
eWriteModeadditional options for writing the object
Returns
the length of the object

◆ GetOwner()

PdfVecObjects * PoDoFo::PdfObject::GetOwner ( ) const
inline

Get the owner of this object.

Returns
the owner (if it wasn't changed anywhere, creator) of this object

◆ GetStream() [1/2]

PdfStream * PoDoFo::PdfObject::GetStream ( )

Get a handle to a PDF stream object. If the PDF object does not have a stream, one will be created.

Returns
a PdfStream object

This will set the dirty flag of this object.

See also
IsDirty

◆ GetStream() [2/2]

const PdfStream * PoDoFo::PdfObject::GetStream ( ) const

Get a handle to a const PDF stream object. If the PDF object does not have a stream, null is returned.

Returns
a PdfStream object or null

◆ GetStream_NoDL()

PdfStream * PoDoFo::PdfObject::GetStream_NoDL ( )
protected

Same as GetStream() but won't trigger a delayed load, so it's safe for use while a delayed load is in progress.

This will set the dirty flag of this object.

See also
IsDirty

◆ HasStream()

bool PoDoFo::PdfObject::HasStream ( ) const
inline

Check if this object has a PdfStream object appended.

Returns
true if the object has a stream

◆ MustGetIndirectKey()

PdfObject * PoDoFo::PdfObject::MustGetIndirectKey ( const PdfName & key) const
inline

MustGetIndirectKey() wraps GetIndirectKey to throw on null return. This makes it MUCH more readable to look up deep chains of linked keys with the cost that it's not easy to tell at which point a missing key/object was encountered.

Returns
the found value, which is never null
Exceptions
PdfError(ePdfError_NoObject).

◆ operator<()

bool PoDoFo::PdfObject::operator< ( const PdfObject & rhs) const
inline

This operator is required for sorting a list of PdfObject instances. It compares the object number. If object numbers are equal, the generation number is compared.

◆ operator=()

const PdfObject & PoDoFo::PdfObject::operator= ( const PdfObject & rhs)

Creates a copy of an existing PdfObject. All associated objects and streams will be copied along with the PdfObject.

Parameters
rhsPdfObject to clone
Returns
a reference to this object

◆ operator==()

bool PoDoFo::PdfObject::operator== ( const PdfObject & rhs) const
inline

Comparison operator. Compares two PDF object instances only based on their object and generation number.

◆ Reference()

const PdfReference & PoDoFo::PdfObject::Reference ( ) const
inline

Get an indirect reference to this object.

Returns
a PdfReference pointing to this object.

◆ SetVariantOwner()

void PoDoFo::PdfObject::SetVariantOwner ( EPdfDataType eDataType)
protected

Set the owner of this object variant

◆ WriteObject()

void PoDoFo::PdfObject::WriteObject ( PdfOutputDevice * pDevice,
EPdfWriteMode eWriteMode,
PdfEncrypt * pEncrypt,
const PdfName & keyStop = PdfName::KeyNull ) const

Write the complete object to a file.

Parameters
pDevicewrite the object to this device
pEncryptan encryption object which is used to encrypt this object or NULL to not encrypt this object
eWriteModeadditional options for writing the object
keyStopif not KeyNull and a key == keyStop is found writing will stop right before this key!