PoDoFo 0.9.6
PoDoFo::PdfVecObjects Class Reference

#include <PdfVecObjects.h>

Classes

class  Observer
class  StreamFactory

Public Member Functions

 PdfVecObjects ()
PdfDocumentGetParentDocument () const
void SetParentDocument (PdfDocument *pDocument)
void SetAutoDelete (bool bAutoDelete)
bool AutoDelete () const
void SetCanReuseObjectNumbers (bool bCanReuseObjectNumbers)
bool GetCanReuseObjectNumbers () const
void Clear ()
size_t GetSize () const
size_t GetObjectCount () const
PdfObjectGetObject (const PdfReference &ref) const
PdfObjectMustGetObject (const PdfReference &ref) const
size_t GetIndex (const PdfReference &ref) const
PdfObjectRemoveObject (const PdfReference &ref, bool bMarkAsFree=true)
PdfObjectRemoveObject (const TIVecObjects &it)
PdfObjectCreateObject (const char *pszType=NULL)
PdfObjectCreateObject (const PdfVariant &rVariant)
void AddFreeObject (const PdfReference &rReference)
const TPdfReferenceList & GetFreeObjects () const
void RenumberObjects (PdfObject *pTrailer, TPdfReferenceSet *pNotDelete=NULL, bool bDoGarbageCollection=false)
void push_back (PdfObject *pObj)
void insert_sorted (PdfObject *pObj)
void Sort ()
void SetMaxReserveSize (size_t size)
size_t GetMaxReserveSize () const
void Reserve (size_t size)
void GetObjectDependencies (const PdfObject *pObj, TPdfReferenceList *pList) const
void Attach (Observer *pObserver)
void Detach (Observer *pObserver)
void SetStreamFactory (StreamFactory *pFactory)
PdfStreamCreateStream (PdfObject *pParent)
PdfStreamCreateStream (const PdfStream &rhs)
void WriteObject (PdfObject *pObject)
void Finish ()
void BeginAppendStream (const PdfStream *pStream)
void EndAppendStream (const PdfStream *pStream)
TIVecObjects begin ()
TCIVecObjects begin () const
TIVecObjects end ()
TCIVecObjects end () const
PdfObjectGetBack ()
void CollectGarbage (PdfObject *pTrailer)
std::string GetNextSubsetPrefix ()
void SetObjectCount (const PdfReference &rRef)

Detailed Description

A STL vector of PdfObjects. I.e. a list of PdfObject classes. The PdfParser will read the PdfFile into memory and create a PdfVecObjects of all dictionaries found in the PDF file.

The PdfWriter class contrary creates a PdfVecObjects internally and writes it to a PDF file later with an appropriate table of contents.

These class contains also advanced functions for searching of PdfObject's in a PdfVecObject.

Constructor & Destructor Documentation

◆ PdfVecObjects()

PoDoFo::PdfVecObjects::PdfVecObjects ( )

Default constuctor

Member Function Documentation

◆ AddFreeObject()

void PoDoFo::PdfVecObjects::AddFreeObject ( const PdfReference & rReference)

Mark a reference as unused so that it can be reused for new objects.

Parameters
rReferencethe reference to reuse
See also
GetCanReuseObjectNumbers

◆ Attach()

void PoDoFo::PdfVecObjects::Attach ( Observer * pObserver)
inline

Attach a new observer

Parameters
pObserverto attach

◆ AutoDelete()

bool PoDoFo::PdfVecObjects::AutoDelete ( ) const
inline
Returns
if autodeletion is enabled and all objects will be deleted when the PdfVecObjects is deleted.

◆ begin() [1/2]

TIVecObjects PoDoFo::PdfVecObjects::begin ( )
inline

Iterator pointing at the beginning of the vector

Returns
beginning iterator

◆ begin() [2/2]

TCIVecObjects PoDoFo::PdfVecObjects::begin ( ) const
inline

Iterator pointing at the beginning of the vector

Returns
beginning iterator

◆ BeginAppendStream()

void PoDoFo::PdfVecObjects::BeginAppendStream ( const PdfStream * pStream)

Every stream implementation has to call this in BeginAppend

Parameters
pStreamthe stream object that is calling

◆ Clear()

void PoDoFo::PdfVecObjects::Clear ( )

Removes all objects from the vector and resets it to the default state.

If SetAutoDelete is true all objects are deleted. All observers are removed from the vector.

See also
SetAutoDelete
AutoDelete

◆ CollectGarbage()

void PoDoFo::PdfVecObjects::CollectGarbage ( PdfObject * pTrailer)

Deletes all objects that are not references by other objects besides the trailer (which references the root dictionary, which in turn should reference all other objects).

Parameters
pTrailertrailer object of the PDF

Warning this might be slow!

◆ CreateObject() [1/2]

PdfObject * PoDoFo::PdfVecObjects::CreateObject ( const char * pszType = NULL)

Creates a new object and inserts it into the vector. This function assigns the next free object number to the PdfObject.

Parameters
pszTypeoptional value of the /Type key of the object
Returns
PdfObject pointer to the new PdfObject

◆ CreateObject() [2/2]

PdfObject * PoDoFo::PdfVecObjects::CreateObject ( const PdfVariant & rVariant)

Creates a new object (of type rVariants) and inserts it into the vector. This function assigns the next free object number to the PdfObject.

Parameters
rVariantvalue of the PdfObject
Returns
PdfObject pointer to the new PdfObject

◆ CreateStream() [1/2]

PdfStream * PoDoFo::PdfVecObjects::CreateStream ( const PdfStream & rhs)

Creates a stream object by copying an existing stream

Parameters
rhscopy this stream
Returns
a new stream object

◆ CreateStream() [2/2]

PdfStream * PoDoFo::PdfVecObjects::CreateStream ( PdfObject * pParent)

Creates a stream object This method is a factory for PdfStream objects.

Parameters
pParentparent object
Returns
a new stream object

◆ Detach()

void PoDoFo::PdfVecObjects::Detach ( Observer * pObserver)

Detach an observer.

Parameters
pObserverobserver to detach

◆ end() [1/2]

TIVecObjects PoDoFo::PdfVecObjects::end ( )
inline

Iterator pointing at the end of the vector

Returns
ending iterator

◆ end() [2/2]

TCIVecObjects PoDoFo::PdfVecObjects::end ( ) const
inline

Iterator pointing at the end of the vector

Returns
ending iterator

◆ EndAppendStream()

void PoDoFo::PdfVecObjects::EndAppendStream ( const PdfStream * pStream)

Every stream implementation has to call this in EndAppend

Parameters
pStreamthe stream object that is calling

◆ Finish()

void PoDoFo::PdfVecObjects::Finish ( )

Call whenever a document is finished

◆ GetBack()

PdfObject * PoDoFo::PdfVecObjects::GetBack ( )
inline

Get the last object in the vector

Returns
the last object in the vector or NULL if the vector is empty.

◆ GetCanReuseObjectNumbers()

bool PoDoFo::PdfVecObjects::GetCanReuseObjectNumbers ( ) const
inline
Returns
whether can re-use free object numbers when creating new objects.

◆ GetFreeObjects()

const TPdfReferenceList & PoDoFo::PdfVecObjects::GetFreeObjects ( ) const
inline
Returns
a list of free references in this vector

◆ GetIndex()

size_t PoDoFo::PdfVecObjects::GetIndex ( const PdfReference & ref) const

Finds the object with the given reference in m_vecOffsets and returns the index to it.

Parameters
refthe object to be found
Returns
the found object or NULL if no object was found.

◆ GetMaxReserveSize()

size_t PoDoFo::PdfVecObjects::GetMaxReserveSize ( ) const
inline

Gets the maximum number of elements Reserve() will work for (to fix CVE-2018-5783) which is called with a value from the PDF in the parser. The default is from Table C.1 in section C.2 of PDF32000_2008.pdf (PDF 1.7 standard free version): 8388607.

◆ GetNextSubsetPrefix()

std::string PoDoFo::PdfVecObjects::GetNextSubsetPrefix ( )

Get next unique subset-prefix

Returns
a string to use as subset-prefix.

◆ GetObject()

PdfObject * PoDoFo::PdfVecObjects::GetObject ( const PdfReference & ref) const

Finds the object with the given reference in m_vecOffsets and returns a pointer to it if it is found.

Parameters
refthe object to be found
Returns
the found object or NULL if no object was found.

◆ GetObjectCount()

size_t PoDoFo::PdfVecObjects::GetObjectCount ( ) const
inline
Returns
the highest object number in the vector

◆ GetObjectDependencies()

void PoDoFo::PdfVecObjects::GetObjectDependencies ( const PdfObject * pObj,
TPdfReferenceList * pList ) const

Get a set with all references of objects that the passed object depends on.

Parameters
pObjthe object to calculate all dependencies for
pListwrite the list of dependencies to this list

◆ GetParentDocument()

PdfDocument * PoDoFo::PdfVecObjects::GetParentDocument ( ) const
inline
Returns
a pointer to a PdfDocument that is the parent of this vector. Might be NULL if the vector has no parent.

◆ GetSize()

size_t PoDoFo::PdfVecObjects::GetSize ( ) const
inline
Returns
the size of the internal vector

◆ insert_sorted()

void PoDoFo::PdfVecObjects::insert_sorted ( PdfObject * pObj)

Insert an object into this vector so that the vector remains sorted w.r.t. the ordering based on object and generation numbers m_bObjectCount will be increased for the object.

Parameters
pObjpointer to the object you want to insert

◆ MustGetObject()

PdfObject * PoDoFo::PdfVecObjects::MustGetObject ( const PdfReference & ref) const

Finds the object with the given reference in m_vecOffsets and returns a pointer to it if it is found. Throws a PdfError exception with error code ePdfError_NoObject if no object was found

Parameters
refthe object to be found
Returns
the found object
Exceptions
PdfError(ePdfError_NoObject)

◆ push_back()

void PoDoFo::PdfVecObjects::push_back ( PdfObject * pObj)
See also
insert_sorted

Simple forward to insert sorted, as PdfVecObjects is always sorted.

◆ RemoveObject() [1/2]

PdfObject * PoDoFo::PdfVecObjects::RemoveObject ( const PdfReference & ref,
bool bMarkAsFree = true )

Remove the object with the given object and generation number from the list of objects. The object is returned if it was found. Otherwise NULL is returned. The caller has to delete the object by himself.

Parameters
refthe object to be found
bMarkAsFreeif true the removed object reference is marked as free object you will always want to have this true as invalid PDF files can be generated otherwise
Returns
The removed object.

◆ RemoveObject() [2/2]

PdfObject * PoDoFo::PdfVecObjects::RemoveObject ( const TIVecObjects & it)

Remove the object with the iterator it from the vector and return it

Parameters
itthe object to remove
Returns
the removed object

◆ RenumberObjects()

void PoDoFo::PdfVecObjects::RenumberObjects ( PdfObject * pTrailer,
TPdfReferenceSet * pNotDelete = NULL,
bool bDoGarbageCollection = false )

Renumbers all objects according to there current position in the vector. All references remain intact. Warning! This function is very calculation intensive.

Parameters
pTrailerthe trailer object
pNotDeletea list of object which must not be deleted
bDoGarbageCollectionenable garbage collection, which deletes all objects that are not reachable from the trailer. This might be slow!
See also
CollectGarbage

◆ Reserve()

void PoDoFo::PdfVecObjects::Reserve ( size_t size)
inline

Causes the internal vector to reserve space for size elements.

Parameters
sizereserve space for that much elements in the internal vector

◆ SetAutoDelete()

void PoDoFo::PdfVecObjects::SetAutoDelete ( bool bAutoDelete)
inline

Enable/disable auto deletion. By default auto deletion is disabled.

Parameters
bAutoDeleteif true all objects will be deleted when the PdfVecObjects is deleted.

◆ SetCanReuseObjectNumbers()

void PoDoFo::PdfVecObjects::SetCanReuseObjectNumbers ( bool bCanReuseObjectNumbers)

Enable/disable object numbers re-use. By default object numbers re-use is enabled.

Parameters
bCanReuseObjectNumbersif true, free object numbers can be re-used when creating new objects.

If set to false, the list of free object numbers is automatically cleared.

◆ SetMaxReserveSize()

void PoDoFo::PdfVecObjects::SetMaxReserveSize ( size_t size)
inline

Set the maximum number of elements Reserve() will work for (to fix CVE-2018-5783) which is called with a value from the PDF in the parser. The default is from Table C.1 in section C.2 of PDF32000_2008.pdf (PDF 1.7 standard free version). This sets a static variable, so don't use from multiple threads (without proper locking).

Parameters
sizeNumber of elements to allow to be reserved

◆ SetObjectCount()

void PoDoFo::PdfVecObjects::SetObjectCount ( const PdfReference & rRef)
inline

Set the object count so that the object described this reference is contained in the object count.

Parameters
rRefreference of newly added object

◆ SetParentDocument()

void PoDoFo::PdfVecObjects::SetParentDocument ( PdfDocument * pDocument)
inline

Sets a parent document of this vector

Parameters
pDocumentthe parent of this vector

◆ SetStreamFactory()

void PoDoFo::PdfVecObjects::SetStreamFactory ( StreamFactory * pFactory)
inline

Sets a StreamFactory which is used whenever CreateStream is called.

Parameters
pFactorya stream factory or NULL to reset to the default factory

◆ Sort()

void PoDoFo::PdfVecObjects::Sort ( )

Sort the objects in the vector based on their object and generation numbers

◆ WriteObject()

void PoDoFo::PdfVecObjects::WriteObject ( PdfObject * pObject)

Can be called to force objects to be written to disk.

Parameters
pObjecta PdfObject that should be written to disk.