PoDoFo  1.0.0-dev
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
PoDoFo::PdfObject Class Reference

This class represents a PDF indirect Object in memory. More...

#include <PdfObject.h>

Public Member Functions

 PdfObject ()
 Create a PDF object with an empty PdfDictionary.
 
 PdfObject (std::nullptr_t)
 Create a "null" PDF object.
 
 PdfObject (const PdfVariant &var)
 Create a PDF object with the passed variant. More...
 
 PdfObject (PdfVariant &&var) noexcept
 
 PdfObject (bool b)
 Construct a PdfObject with bool as value. More...
 
 PdfObject (int64_t l)
 Construct a PdfObject with object with int64_t as value. More...
 
 PdfObject (double d)
 Construct a PdfObject with double as value. More...
 
 PdfObject (const PdfString &str)
 Construct a PdfObject with PdfString as value. More...
 
 PdfObject (const PdfName &name)
 Construct a PdfObject with PdfName as value. More...
 
 PdfObject (const PdfReference &ref)
 Construct a PdfObject with PdfReference as value. More...
 
 PdfObject (const PdfArray &arr)
 Construct a PdfObject with PdfArray as value. More...
 
 PdfObject (PdfArray &&arr) noexcept
 
 PdfObject (const PdfDictionary &dict)
 Construct a PdfObject with PdfDictionary as value. More...
 
 PdfObject (PdfDictionary &&dict) noexcept
 
 PdfObject (const PdfObject &rhs)
 Creates a copy of an existing PdfObject. More...
 
 PdfObject (PdfObject &&rhs) noexcept
 
PdfDataType GetDataType () const
 
std::string_view 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 (PdfWriteFlags writeFlags=PdfWriteFlags::None) const
 Converts the current object into a string representation which can be written directly to a PDF file on disc. More...
 
void ToString (std::string &str, PdfWriteFlags writeFlags=PdfWriteFlags::None) const
 
bool GetBool () const
 Get the value if this object is a bool. More...
 
bool TryGetBool (bool &value) const
 
int64_t GetNumberLenient () const
 Get the value of the object as int64_t. More...
 
bool TryGetNumberLenient (int64_t &value) const
 
int64_t GetNumber () const
 Get the value of the object as int64_t. More...
 
bool TryGetNumber (int64_t &value) const
 
double GetReal () const
 Get the value of the object as a floating point. More...
 
bool TryGetReal (double &value) const
 
double GetRealStrict () const
 Get the value of the object as floating point number. More...
 
bool TryGetRealStrict (double &value) const
 
const PdfStringGetString () const
 
bool TryGetString (PdfString &str) const
 
bool TryGetString (const PdfString *&str) const
 
const PdfNameGetName () const
 
bool TryGetName (PdfName &name) const
 
bool TryGetName (const PdfName *&name) const
 
PdfReference GetReference () const
 Get the reference values of this object. More...
 
bool TryGetReference (PdfReference &ref) const
 
const PdfArrayGetArray () const
 Returns the value of the object as array. More...
 
PdfArrayGetArray ()
 
bool TryGetArray (const PdfArray *&arr) const
 
bool TryGetArray (PdfArray *&arr)
 
const PdfDictionaryGetDictionary () const
 Returns the dictionary value of this object. More...
 
PdfDictionaryGetDictionary ()
 
bool TryGetDictionary (const PdfDictionary *&dict) const
 
bool TryGetDictionary (PdfDictionary *&dict)
 
void SetBool (bool b)
 Set the value of this object as bool. More...
 
void SetNumber (int64_t l)
 Set the value of this object as int64_t. More...
 
void SetReal (double d)
 Set the value of this object as double. More...
 
void SetName (const PdfName &name)
 Set the name value of this object. More...
 
void SetString (const PdfString &str)
 Set the string value of this object. More...
 
void SetReference (const PdfReference &ref)
 
void ForceCreateStream ()
 
void Write (OutputStream &stream, PdfWriteFlags writeMode, const PdfStatefulEncrypt *encrypt, charbuff &buffer) const
 Write the complete object to a file. More...
 
PdfObjectStreamGetOrCreateStream ()
 Get a handle to a PDF stream object. More...
 
void RemoveStream ()
 
const PdfObjectStreamMustGetStream () const
 Get a handle to a const PDF stream object. More...
 
PdfObjectStreamMustGetStream ()
 Get a handle to a const PDF stream object. More...
 
virtual bool TryUnload ()
 Tries to free all memory allocated by the given PdfObject (variables and streams) and reads it from disk again if it is requested another time. More...
 
bool HasStream () const
 Check if this object has a PdfObjectStream object appended. More...
 
bool IsIndirect () const
 
const PdfVariantGetVariant () const
 
bool operator< (const PdfObject &rhs) const
 This operator is required for sorting a list of PdfObject instances. More...
 
bool operator== (const PdfObject &rhs) const
 The equality operator with PdfObject checks for parent document and indirect reference first.
 
bool operator!= (const PdfObject &rhs) const
 The disequality operator with PdfObject checks for parent document and indirect reference first.
 
bool operator== (const PdfVariant &rhs) const
 The equality operator with PdfVariant checks equality with variant object only.
 
bool operator!= (const PdfVariant &rhs) const
 The disequality operator with PdfVariant checks disequality with variant object only.
 
PdfObjectoperator= (const PdfObject &rhs)
 Copy an existing PdfObject. More...
 
PdfObjectoperator= (PdfObject &&rhs) noexcept
 
 operator const PdfVariant & () const
 
bool IsDirty () const
 The dirty flag is set if this variant has been modified after construction. More...
 
PdfDocumentGetDocument () const
 Get the document of this object. More...
 
PdfDocumentMustGetDocument () const
 Get the document of this object. More...
 
const PdfReferenceGetIndirectReference () const
 Get an indirect reference to this object. More...
 
const PdfDataContainerGetParent () const
 
bool IsDelayedLoadDone () const
 Returns true if delayed loading is disabled, or if it is enabled and loading has completed. More...
 
bool IsDelayedLoadStreamDone () const
 
const PdfObjectStreamGetStream () const
 
PdfObjectStreamGetStream ()
 

Static Public Attributes

static const PdfObject Null = PdfObject(nullptr)
 

Protected Member Functions

void DelayedLoad () const
 Dynamically load the contents of this object from a PDF file by calling the virtual method delayedLoad() if the object is not already loaded. More...
 
virtual void delayedLoad ()
 Load all data of the object if delayed loading is enabled. More...
 
virtual void delayedLoadStream ()
 
virtual bool removeStream ()
 
virtual bool HasStreamToParse () const
 
void SetDirty ()
 Sets the dirty flag of this PdfVariant. More...
 
void resetDirty ()
 
void SetDocument (PdfDocument *document)
 Set the owner of this object, i.e. More...
 
void SetVariantOwner ()
 
void FreeStream ()
 
PdfObjectStreamgetOrCreateStream ()
 
void forceCreateStream ()
 
PdfObjectStreamgetStream ()
 
void DelayedLoadStream () const
 
void delayedLoadStream () const
 
void EnableDelayedLoadingStream ()
 
void SetIndirectReference (const PdfReference &reference)
 
void EnableDelayedLoading ()
 Flag the object incompletely loaded. More...
 
virtual void SetRevised ()
 Set the object as irreversibly revised. More...
 

Protected Attributes

PdfVariant m_Variant
 

Friends

class PdfIndirectObjectList
 
class PdfArray
 
class PdfDictionary
 
class PdfDocument
 
class PdfObjectStream
 
class PdfObjectOutputStream
 
class PdfDataContainer
 
class PdfDictionaryElement
 
class PdfArrayElement
 
class PdfTokenizer
 

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/10]

PdfObject::PdfObject ( const PdfVariant var)

Create a PDF object with the passed variant.

Parameters
varthe value of the object

◆ PdfObject() [2/10]

PdfObject::PdfObject ( bool  b)

Construct a PdfObject with bool as value.

Parameters
bthe boolean value of this PdfObject

◆ PdfObject() [3/10]

PdfObject::PdfObject ( int64_t  l)

Construct a PdfObject with object with int64_t as value.

Parameters
lthe int64_t value of this PdfObject

◆ PdfObject() [4/10]

PdfObject::PdfObject ( double  d)

Construct a PdfObject with double as value.

Parameters
dthe double value of this PdfObject

◆ PdfObject() [5/10]

PdfObject::PdfObject ( const PdfString str)

Construct a PdfObject with PdfString as value.

Parameters
strthe string value of this PdfObject

◆ PdfObject() [6/10]

PdfObject::PdfObject ( const PdfName name)

Construct a PdfObject with PdfName as value.

Parameters
namethe value of this PdfObject

◆ PdfObject() [7/10]

PdfObject::PdfObject ( const PdfReference ref)

Construct a PdfObject with PdfReference as value.

Parameters
refthe value of the this PdfObject

◆ PdfObject() [8/10]

PdfObject::PdfObject ( const PdfArray arr)

Construct a PdfObject with PdfArray as value.

Parameters
arrthe value of the this PdfObject

◆ PdfObject() [9/10]

PdfObject::PdfObject ( const PdfDictionary dict)

Construct a PdfObject with PdfDictionary as value.

Parameters
dictthe value of the this PdfObject

◆ PdfObject() [10/10]

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

◆ DelayedLoad()

void PdfObject::DelayedLoad ( ) const
protected

Dynamically load the contents of this object from a PDF file by calling the virtual method delayedLoad() 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.

◆ 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 delayedLoad().

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

string_view 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 number 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 number 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<()

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

◆ removeStream()

bool PdfObject::removeStream ( )
protectedvirtual
Returns
true if the stream was removed

◆ 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

◆ SetRevised()

void PdfObject::SetRevised ( )
protectedvirtual

Set the object as irreversibly revised.

This is mostly used in PdfParserObject to stop it from trying to reclaim memory

◆ 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 ( PdfWriteFlags  writeFlags = PdfWriteFlags::None) 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.

◆ TryUnload()

bool PdfObject::TryUnload ( )
virtual

Tries to free all memory allocated by the given PdfObject (variables and streams) and reads it from disk again if it is requested another time.

This will only work if the object is lazily loaded, Otherwise any call to this method will be ignored

◆ Write()

void PdfObject::Write ( OutputStream stream,
PdfWriteFlags  writeMode,
const PdfStatefulEncrypt *  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!

The documentation for this class was generated from the following files: