PoDoFo
1.0.0-dev
|
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 PdfString & | GetString () const |
bool | TryGetString (PdfString &str) const |
bool | TryGetString (const PdfString *&str) const |
const PdfName & | GetName () 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 PdfArray & | GetArray () const |
Returns the value of the object as array. More... | |
PdfArray & | GetArray () |
bool | TryGetArray (const PdfArray *&arr) const |
bool | TryGetArray (PdfArray *&arr) |
const PdfDictionary & | GetDictionary () const |
Returns the dictionary value of this object. More... | |
PdfDictionary & | GetDictionary () |
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... | |
PdfObjectStream & | GetOrCreateStream () |
Get a handle to a PDF stream object. More... | |
void | RemoveStream () |
const PdfObjectStream & | MustGetStream () const |
Get a handle to a const PDF stream object. More... | |
PdfObjectStream & | MustGetStream () |
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 PdfVariant & | GetVariant () 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. | |
PdfObject & | operator= (const PdfObject &rhs) |
Copy an existing PdfObject. More... | |
PdfObject & | operator= (PdfObject &&rhs) noexcept |
operator const PdfVariant & () const | |
bool | IsDirty () const |
The dirty flag is set if this variant has been modified after construction. More... | |
PdfDocument * | GetDocument () const |
Get the document of this object. More... | |
PdfDocument & | MustGetDocument () const |
Get the document of this object. More... | |
const PdfReference & | GetIndirectReference () const |
Get an indirect reference to this object. More... | |
const PdfDataContainer * | GetParent () 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 PdfObjectStream * | GetStream () const |
PdfObjectStream * | GetStream () |
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 () |
PdfObjectStream & | getOrCreateStream () |
void | forceCreateStream () |
PdfObjectStream * | getStream () |
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 |
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.
PdfObject::PdfObject | ( | const PdfVariant & | var | ) |
Create a PDF object with the passed variant.
var | the value of the object |
PdfObject::PdfObject | ( | bool | b | ) |
PdfObject::PdfObject | ( | int64_t | l | ) |
PdfObject::PdfObject | ( | double | d | ) |
PdfObject::PdfObject | ( | const PdfString & | str | ) |
PdfObject::PdfObject | ( | const PdfName & | name | ) |
PdfObject::PdfObject | ( | const PdfReference & | ref | ) |
Construct a PdfObject with PdfReference as value.
ref | the value of the this PdfObject |
PdfObject::PdfObject | ( | const PdfArray & | arr | ) |
PdfObject::PdfObject | ( | const PdfDictionary & | dict | ) |
Construct a PdfObject with PdfDictionary as value.
dict | the value of the this PdfObject |
PdfObject::PdfObject | ( | const PdfObject & | rhs | ) |
|
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.
|
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.
|
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().
const PdfArray & PdfObject::GetArray | ( | ) | const |
Returns the value of the object as array.
bool PdfObject::GetBool | ( | ) | const |
Get the value if this object is a bool.
PdfDataType PdfObject::GetDataType | ( | ) | const |
string_view PdfObject::GetDataTypeString | ( | ) | const |
const PdfDictionary & PdfObject::GetDictionary | ( | ) | const |
Returns the dictionary value of this object.
|
inline |
Get the document of this object.
|
inline |
Get an indirect reference to this object.
const PdfName & PdfObject::GetName | ( | ) | const |
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
int64_t PdfObject::GetNumberLenient | ( | ) | const |
Get the value of the object as int64_t.
This method is lenient and narrows floating point numbers
PdfObjectStream & PdfObject::GetOrCreateStream | ( | ) |
Get a handle to a PDF stream object.
If the PDF object does not have a stream, one will be created.
double PdfObject::GetReal | ( | ) | const |
Get the value of the object as a floating point.
This method is lenient and returns also strictly integral numbers
double PdfObject::GetRealStrict | ( | ) | const |
Get the value of the object as floating point number.
This method throws if the number is integer
PdfReference PdfObject::GetReference | ( | ) | const |
Get the reference values of this object.
const PdfString & PdfObject::GetString | ( | ) | const |
bool PdfObject::HasStream | ( | ) | const |
Check if this object has a PdfObjectStream object appended.
bool PdfObject::IsArray | ( | ) | const |
bool PdfObject::IsBool | ( | ) | 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.
bool PdfObject::IsDictionary | ( | ) | 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.
bool PdfObject::IsName | ( | ) | const |
bool PdfObject::IsNull | ( | ) | const |
bool PdfObject::IsNumber | ( | ) | const |
bool PdfObject::IsNumberOrReal | ( | ) | const |
bool PdfObject::IsRawData | ( | ) | const |
bool PdfObject::IsRealStrict | ( | ) | const |
This method strictly check for a floating point number and return false on integer
bool PdfObject::IsReference | ( | ) | const |
bool PdfObject::IsString | ( | ) | const |
PdfDocument & PdfObject::MustGetDocument | ( | ) | const |
Get the document of this object.
PdfObjectStream & PdfObject::MustGetStream | ( | ) |
Get a handle to a const PDF stream object.
Throws if there's no stream
const PdfObjectStream & PdfObject::MustGetStream | ( | ) | const |
Get a handle to a const PDF stream object.
Throws if there's no stream
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.
|
protectedvirtual |
void PdfObject::SetBool | ( | bool | b | ) |
Set the value of this object as bool.
b | the value as bool. |
This will set the dirty flag of this object.
|
protected |
Sets the dirty flag of this PdfVariant.
|
protected |
Set the owner of this object, i.e.
the PdfIndirectObjectList to which this object belongs.
objects | a vector of pdf objects |
void PdfObject::SetName | ( | const PdfName & | name | ) |
Set the name value of this object.
d | the name value |
This will set the dirty flag of this object.
void PdfObject::SetNumber | ( | int64_t | l | ) |
Set the value of this object as int64_t.
l | the value as int64_t. |
This will set the dirty flag of this object.
void PdfObject::SetReal | ( | double | d | ) |
Set the value of this object as double.
d | the value as double. |
This will set the dirty flag of this object.
|
protectedvirtual |
Set the object as irreversibly revised.
This is mostly used in PdfParserObject to stop it from trying to reclaim memory
void PdfObject::SetString | ( | const PdfString & | str | ) |
Set the string value of this object.
str | the string value |
This will set the dirty flag of this object.
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.
str | the object string is returned in this object. |
|
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
void PdfObject::Write | ( | OutputStream & | stream, |
PdfWriteFlags | writeMode, | ||
const PdfStatefulEncrypt * | encrypt, | ||
charbuff & | buffer | ||
) | const |
Write the complete object to a file.
stream | write the object to this device |
encrypt | an encryption object which is used to encrypt this object or nullptr to not encrypt this object |
writeMode | additional options for writing the object |
keyStop | if not KeyNull and a key == keyStop is found writing will stop right before this key! |