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

#include <PdfParserObject.h>

Inheritance diagram for mm::PdfParserObject:
mm::PdfObject mm::PdfXRefStreamParserObject

Public Member Functions

 PdfParserObject (PdfDocument &document, const std::shared_ptr< PdfInputDevice > &device, ssize_t offset=-1)
 
 PdfParserObject ()
 
void FreeObjectMemory (bool force=false)
 
void ParseFile (PdfEncrypt *encrypt, bool isTrailer=false)
 
bool HasStreamToParse () const
 
bool IsLoadOnDemand () const
 
void SetLoadOnDemand (bool bDelayed)
 
ssize_t GetOffset () const
 
- Public Member Functions inherited from mm::PdfObject
 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 DelayedLoadImpl () override
 
- Protected Member Functions inherited from mm::PdfObject
void DelayedLoad () const
 
virtual void DelayedLoadImpl ()
 
void AssertMutable () const
 
void SetDirty ()
 
void SetDocument (PdfDocument &document)
 

Detailed Description

A PdfParserObject constructs a PdfObject from a PDF file. Parsing starts always at the current file position.

Constructor & Destructor Documentation

◆ PdfParserObject() [1/2]

mm::PdfParserObject::PdfParserObject ( PdfDocument document,
const std::shared_ptr< PdfInputDevice > &  device,
ssize_t  offset = -1 
)

Parse the object data from the given file handle starting at the current position.

Parameters
documentdocument where to resolve object references
devicean open reference counted input device which is positioned in front of the object which is going to be parsed.
bufferbuffer to use for parsing to avoid reallocations
offsetthe position in the device from which the object shall be read if lOffset = -1, the object will be read from the current position in the file.

◆ PdfParserObject() [2/2]

PdfParserObject::PdfParserObject ( )

Parse the object data for an internal object. You have to call ParseDictionaryKeys as next function call.

The following two parameters are used to avoid allocation of a new buffer in PdfSimpleParser.

Warning
This constructor is for internal usage only!

Member Function Documentation

◆ DelayedLoadImpl()

void PdfParserObject::DelayedLoadImpl ( )
overrideprotectedvirtual

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 from mm::PdfObject.

◆ FreeObjectMemory()

void PdfParserObject::FreeObjectMemory ( bool  force = false)

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

This will only work if load on demand is used. If the object is dirty if will not be free'd.

Parameters
forceif true the object will be free'd even if IsDirty() returns true. So you will loose any changes made to this object.
See also
IsLoadOnDemand
IsDirty

◆ GetOffset()

ssize_t mm::PdfParserObject::GetOffset ( ) const
inline

Gets an offset in which the object beginning is stored in the file. Note the offset points just after the object identificator ("0 0 obj").

Returns
an offset in which the object is stored in the source device, or -1, if the object was created on demand.

◆ HasStreamToParse()

bool mm::PdfParserObject::HasStreamToParse ( ) const
inline

Returns if this object has a stream object appended. which has to be parsed.

Returns
true if there is a stream

◆ IsLoadOnDemand()

bool mm::PdfParserObject::IsLoadOnDemand ( ) const
inline
Returns
true if this PdfParser loads all objects at the time they are accessed for the first time. The default is to load all object immediately. In this case false is returned.

◆ ParseFile()

void PdfParserObject::ParseFile ( PdfEncrypt encrypt,
bool  isTrailer = false 
)

Parse the object data from the given file handle If delayed loading is enabled, only the object and generation number is read now and everything else is read later.

Parameters
encryptan encryption dictionary which is used to decrypt strings and streams during parsing or nullptr if the PDF file was not encrypted
isTrailerwhether this is a trailer dictionary or not. trailer dictionaries do not have a object number etc.

◆ SetLoadOnDemand()

void mm::PdfParserObject::SetLoadOnDemand ( bool  bDelayed)
inline

Sets whether this object shall be loaded on demand when it's data is accessed for the first time.

Parameters
bDelayedif true the object is loaded delayed.