pdfmm 0.9.20
Public Member Functions | Protected Member Functions | List of all members
mm::PdfObject Class Reference

#include <PdfObject.h>

Inheritance diagram for mm::PdfObject:
mm::PdfParserObject mm::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)
 
void Clear ()
 
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
 
void ToString (std::string &data, PdfWriteMode writeMode=PdfWriteMode::Clean) 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 (PdfOutputDevice &device, PdfWriteMode writeMode, PdfEncrypt *encrypt) const
 
size_t GetObjectLength (PdfWriteMode writeMode)
 
PdfStreamGetOrCreateStream ()
 
const PdfStreamMustGetStream () const
 
PdfStreamMustGetStream ()
 
bool HasStream () const
 
void SetImmutable (bool isImmutable)
 
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
 
const PdfObjectoperator= (const PdfObject &rhs)
 
bool IsDirty () const
 
PdfDocumentGetDocument () const
 
PdfDocumentMustGetDocument () const
 
const PdfReferenceGetIndirectReference () const
 
bool IsImmutable () const
 
void EnableDelayedLoading ()
 
bool DelayedLoadDone () const
 

Protected Member Functions

void DelayedLoad () const
 
virtual void DelayedLoadImpl ()
 
void AssertMutable () const
 
void SetDirty ()
 
void SetDocument (PdfDocument &document)
 

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 object and generation number -1 and the value of being an empty PdfDictionary.

◆ PdfObject() [2/11]

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() [3/11]

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() [4/11]

PdfObject::PdfObject ( int64_t  l)

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

Parameters
lthe int64_t value of this PdfObject

◆ PdfObject() [5/11]

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() [6/11]

PdfObject::PdfObject ( const PdfString str)

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

Parameters
strthe string value of this PdfObject

◆ PdfObject() [7/11]

PdfObject::PdfObject ( const PdfName name)

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

Parameters
namethe value of this PdfObject

◆ PdfObject() [8/11]

PdfObject::PdfObject ( const PdfReference ref)

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

Parameters
refthe value of the this PdfObject

◆ PdfObject() [9/11]

PdfObject::PdfObject ( const PdfArray arr)

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

Parameters
arrthe value of the this PdfObject

◆ PdfObject() [10/11]

PdfObject::PdfObject ( const PdfDictionary dict)

Construct a PdfObject with object and generation number -1 and a 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

◆ AssertMutable()

void PdfObject::AssertMutable ( ) const
protected

Will throw an exception if called on an immutable object, so this should be called before actually changing a value!

◆ Clear()

void PdfObject::Clear ( )

Clear all internal member variables and free the memory they have allocated. Sets the datatype to PdfDataType::Null

This will reset the dirty flag of this object to be clean.

See also
IsDirty

◆ 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.

◆ DelayedLoadDone()

bool mm::PdfObject::DelayedLoadDone ( ) 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.

◆ 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 mm::PdfParserObject.

◆ EnableDelayedLoading()

void mm::PdfObject::EnableDelayedLoading ( )
inline

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 * mm::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 & mm::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

◆ GetObjectLength()

size_t PdfObject::GetObjectLength ( PdfWriteMode  writeMode)

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

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

◆ GetOrCreateStream()

PdfStream & 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 PdfStream 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 PdfStream 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

◆ IsDictionary()

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

◆ IsDirty()

bool mm::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

◆ IsImmutable()

bool mm::PdfObject::IsImmutable ( ) const
inline

Retrieve if an object is immutable.

This is used by PdfImmediateWriter and PdfStreamedDocument so that no keys can be added to an object after setting stream data on it.

Returns
true if the object is immutable

◆ 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]

PdfStream & PdfObject::MustGetStream ( )

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

◆ MustGetStream() [2/2]

const PdfStream & 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=()

const 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 clone
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

◆ SetImmutable()

void PdfObject::SetImmutable ( bool  isImmutable)

Sets this object to immutable, so that no keys can be edited or changed.

Parameters
isImmutableif true set the object to be immutable

This is used by PdfImmediateWriter and PdfStreamedDocument so that no keys can be added to an object after setting stream data on it.

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

void PdfObject::ToString ( std::string &  data,
PdfWriteMode  writeMode = PdfWriteMode::Clean 
) const

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

Parameters
datathe object string is returned in this object.
writeModeadditional options for writing to a string

◆ Write()

void PdfObject::Write ( PdfOutputDevice device,
PdfWriteMode  writeMode,
PdfEncrypt encrypt 
) const

Write the complete object to a file.

Parameters
devicewrite 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!