PoDoFo 0.9.20
PoDoFo::PdfObject Class Reference

#include <PdfObject.h>

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

Public Member Functions

 PdfObject ()
 
 PdfObject (const PdfVariant &var)
 
 PdfObject (bool b)
 
 PdfObject (int64_t l)
 
 PdfObject (double d)
 
 PdfObject (const PdfString &str)
 
 PdfObject (const PdfName &name)
 
 PdfObject (const PdfReference &ref)
 
 PdfObject (const PdfArray &arr)
 
 PdfObject (const PdfDictionary &dict)
 
 PdfObject (const PdfObject &rhs)
 
PdfDataType GetDataType () const
 
const char * GetDataTypeString () const
 
bool IsBool () const
 
bool IsNumber () const
 
bool IsRealStrict () const
 
bool IsNumberOrReal () const
 
bool IsString () const
 
bool IsName () const
 
bool IsArray () const
 
bool IsDictionary () const
 
bool IsRawData () const
 
bool IsNull () const
 
bool IsReference () const
 
std::string ToString () const
 
bool GetBool () const
 
int64_t GetNumberLenient () const
 
int64_t GetNumber () const
 
double GetReal () const
 
double GetRealStrict () const
 
const PdfStringGetString () const
 
const PdfNameGetName () const
 
PdfReference GetReference () const
 
const PdfArrayGetArray () const
 
const PdfDictionaryGetDictionary () const
 
void SetBool (bool b)
 
void SetNumber (int64_t l)
 
void SetReal (double d)
 
void SetName (const PdfName &name)
 
void SetString (const PdfString &str)
 
void Write (OutputStream &stream, PdfWriteFlags writeMode, const PdfEncrypt *encrypt, charbuff &buffer) const
 
PdfObjectStreamGetOrCreateStream ()
 
const PdfObjectStreamMustGetStream () const
 
PdfObjectStreamMustGetStream ()
 
bool HasStream () const
 
bool operator< (const PdfObject &rhs) const
 
bool operator== (const PdfObject &rhs) const
 
bool operator!= (const PdfObject &rhs) const
 
bool operator== (const PdfVariant &rhs) const
 
bool operator!= (const PdfVariant &rhs) const
 
PdfObjectoperator= (const PdfObject &rhs)
 
bool IsDirty () const
 
PdfDocumentGetDocument () const
 
PdfDocumentMustGetDocument () const
 
const PdfReferenceGetIndirectReference () const
 
bool IsDelayedLoadDone () const
 

Protected Member Functions

void DelayedLoad () const
 
virtual void DelayedLoadImpl ()
 
void SetDirty ()
 
void SetDocument (PdfDocument *document)
 
void EnableDelayedLoading ()
 

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 Write() function.

See also
Write()

Constructor & Destructor Documentation

◆ PdfObject() [1/11]

PdfObject::PdfObject ( )

Create a PDF object with an empty PdfDictionary.

◆ PdfObject() [2/11]

PdfObject::PdfObject ( const PdfVariant & var)

Create a PDF object with the passed variant.

Parameters
varthe value of the object

◆ PdfObject() [3/11]

PdfObject::PdfObject ( bool b)

Construct a PdfObject with bool as value.

Parameters
bthe boolean value of this PdfObject

◆ PdfObject() [4/11]

PdfObject::PdfObject ( int64_t l)

Construct a PdfObject with object with int64_t as value.

Parameters
lthe int64_t value of this PdfObject

◆ PdfObject() [5/11]

PdfObject::PdfObject ( double d)

Construct a PdfObject with double as value.

Parameters
dthe double value of this PdfObject

◆ PdfObject() [6/11]

PdfObject::PdfObject ( const PdfString & str)

Construct a PdfObject with PdfString as value.

Parameters
strthe string value of this PdfObject

◆ PdfObject() [7/11]

PdfObject::PdfObject ( const PdfName & name)

Construct a PdfObject with PdfName as value.

Parameters
namethe value of this PdfObject

◆ PdfObject() [8/11]

PdfObject::PdfObject ( const PdfReference & ref)

Construct a PdfObject with PdfReference as value.

Parameters
refthe value of the this PdfObject

◆ PdfObject() [9/11]

PdfObject::PdfObject ( const PdfArray & arr)

Construct a PdfObject with PdfArray as value.

Parameters
arrthe value of the this PdfObject

◆ PdfObject() [10/11]

PdfObject::PdfObject ( const PdfDictionary & dict)

Construct a PdfObject with PdfDictionary as value.

Parameters
dictthe value of the this PdfObject

◆ PdfObject() [11/11]

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

◆ DelayedLoad()

void PdfObject::DelayedLoad ( ) const
protected

Dynamically load the contents of this object from a PDF file by calling the virtual method DelayedLoadImpl() if the object is not already loaded.

For objects complete created in memory and those that do not support deferred loading this function does nothing, since deferred loading will not be enabled.

◆ DelayedLoadImpl()

void PdfObject::DelayedLoadImpl ( )
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.

Reimplemented in PoDoFo::PdfParserObject, and PoDoFo::PdfXRefStreamParserObject.

◆ EnableDelayedLoading()

void PdfObject::EnableDelayedLoading ( )
protected

Flag the object incompletely loaded. DelayedLoad() will be called when any method that requires more information than is currently available is loaded.

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

◆ GetArray()

const PdfArray & PdfObject::GetArray ( ) const

Returns the value of the object as array

Returns
a array

◆ GetBool()

bool PdfObject::GetBool ( ) const

Get the value if this object is a bool.

Returns
the bool value.

◆ GetDataType()

PdfDataType PdfObject::GetDataType ( ) const
Returns
the datatype of this object or PdfDataType::Unknown if it does not have a value.

◆ GetDataTypeString()

const char * PdfObject::GetDataTypeString ( ) const
Returns
a human readable string representation of GetDataType() The returned string must not be free'd.

◆ GetDictionary()

const PdfDictionary & PdfObject::GetDictionary ( ) const

Returns the dictionary value of this object

Returns
a PdfDictionary

◆ GetDocument()

PdfDocument * PoDoFo::PdfObject::GetDocument ( ) const
inline

Get the document of this object.

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

◆ GetIndirectReference()

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

Get an indirect reference to this object.

Returns
a PdfReference pointing to this object.

◆ GetName()

const PdfName & PdfObject::GetName ( ) const
Returns
the value of the object as name

◆ GetNumber()

int64_t PdfObject::GetNumber ( ) const

Get the value of the object as int64_t

This method throws if the numer is a floating point number

Returns
the value of the number

◆ GetNumberLenient()

int64_t PdfObject::GetNumberLenient ( ) const

Get the value of the object as int64_t.

This method is lenient and narrows floating point numbers

Returns
the value of the number

◆ GetOrCreateStream()

PdfObjectStream & PdfObject::GetOrCreateStream ( )

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

Returns
a PdfObjectStream object

◆ GetReal()

double PdfObject::GetReal ( ) const

Get the value of the object as a floating point

This method is lenient and returns also strictly integral numbers

Returns
the value of the number

◆ GetRealStrict()

double PdfObject::GetRealStrict ( ) const

Get the value of the object as floating point number

This method throws if the numer is integer

Returns
the value of the number

◆ GetReference()

PdfReference PdfObject::GetReference ( ) const

Get the reference values of this object.

Returns
a PdfReference

◆ GetString()

const PdfString & PdfObject::GetString ( ) const
Returns
the value of the object as string.

◆ HasStream()

bool PdfObject::HasStream ( ) const

Check if this object has a PdfObjectStream object appended.

Returns
true if the object has a stream

◆ IsArray()

bool PdfObject::IsArray ( ) const
Returns
true if this variant is an array

◆ IsBool()

bool PdfObject::IsBool ( ) const
Returns
true if this variant is a bool

◆ IsDelayedLoadDone()

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

Returns true if delayed loading is disabled, or if it is enabled and loading has completed. External callers should never need to see this, it's an internal state flag only.

◆ IsDictionary()

bool PdfObject::IsDictionary ( ) const
Returns
true if this variant is a dictionary

◆ IsDirty()

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

The dirty flag is set if this variant has been modified after construction.

Usually the dirty flag is also set if you call any non-const member function (e.g. GetDictionary()) as PdfVariant cannot determine if you actually changed the dictionary or not.

Returns
true if the value is dirty and has been modified since construction

◆ IsName()

bool PdfObject::IsName ( ) const
Returns
true if this variant is a name

◆ IsNull()

bool PdfObject::IsNull ( ) const
Returns
true if this variant is null

◆ IsNumber()

bool PdfObject::IsNumber ( ) const
Returns
true if this variant is a number

◆ IsNumberOrReal()

bool PdfObject::IsNumberOrReal ( ) const
Returns
true if this variant is an integer or a floating point number

◆ IsRawData()

bool PdfObject::IsRawData ( ) const
Returns
true if this variant is raw data

◆ IsRealStrict()

bool PdfObject::IsRealStrict ( ) const
Returns
true if this variant is a real

This method strictly check for a floating point number and return false on integer

◆ IsReference()

bool PdfObject::IsReference ( ) const
Returns
true if this variant is a reference

◆ IsString()

bool PdfObject::IsString ( ) const
Returns
true if this variant is a string

◆ MustGetDocument()

PdfDocument & PdfObject::MustGetDocument ( ) const

Get the document of this object.

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

◆ MustGetStream() [1/2]

PdfObjectStream & PdfObject::MustGetStream ( )

Get a handle to a const PDF stream object. Throws if there's no stream

◆ MustGetStream() [2/2]

const PdfObjectStream & PdfObject::MustGetStream ( ) const

Get a handle to a const PDF stream object. Throws if there's no stream

◆ operator!=() [1/2]

bool PdfObject::operator!= ( const PdfObject & rhs) const

The disequality operator with PdfObject checks for parent document and indirect reference first

◆ operator!=() [2/2]

bool PdfObject::operator!= ( const PdfVariant & rhs) const

The disequality operator with PdfVariant checks disequality with variant object only

◆ operator<()

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

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=()

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

Copy an existing PdfObject. All associated objects and streams will be copied along with the PdfObject.

Parameters
rhsPdfObject to copy from
Returns
a reference to this object

◆ operator==() [1/2]

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

The equality operator with PdfObject checks for parent document and indirect reference first

◆ operator==() [2/2]

bool PdfObject::operator== ( const PdfVariant & rhs) const

The equality operator with PdfVariant checks equality with variant object only

◆ SetBool()

void PdfObject::SetBool ( bool b)

Set the value of this object as bool

Parameters
bthe value as bool.

This will set the dirty flag of this object.

See also
IsDirty

◆ SetDirty()

void PdfObject::SetDirty ( )
protected

Sets the dirty flag of this PdfVariant

See also
IsDirty

◆ SetDocument()

void PdfObject::SetDocument ( PdfDocument * document)
protected

Set the owner of this object, i.e. the PdfIndirectObjectList to which this object belongs.

Parameters
objectsa vector of pdf objects

◆ SetName()

void PdfObject::SetName ( const PdfName & name)

Set the name value of this object

Parameters
dthe name value

This will set the dirty flag of this object.

See also
IsDirty

◆ SetNumber()

void PdfObject::SetNumber ( int64_t l)

Set the value of this object as int64_t

Parameters
lthe value as int64_t.

This will set the dirty flag of this object.

See also
IsDirty

◆ SetReal()

void PdfObject::SetReal ( double d)

Set the value of this object as double

Parameters
dthe value as double.

This will set the dirty flag of this object.

See also
IsDirty

◆ SetString()

void PdfObject::SetString ( const PdfString & str)

Set the string value of this object.

Parameters
strthe string value

This will set the dirty flag of this object.

See also
IsDirty

◆ ToString()

string PdfObject::ToString ( ) const

Converts the current object into a string representation which can be written directly to a PDF file on disc.

Parameters
strthe object string is returned in this object.

◆ Write()

void PdfObject::Write ( OutputStream & stream,
PdfWriteFlags writeMode,
const PdfEncrypt * encrypt,
charbuff & buffer ) const

Write the complete object to a file.

Parameters
streamwrite the object to this device
encryptan encryption object which is used to encrypt this object or nullptr to not encrypt this object
writeModeadditional options for writing the object
keyStopif not KeyNull and a key == keyStop is found writing will stop right before this key!