9#include "PdfObjectStream.h"
14class PdfIndirectObjectList;
18class PdfDataContainer;
37 friend class PdfObjectOutputStream;
39 friend class PdfDictionaryElement;
40 friend class PdfArrayElement;
44 PODOFO_PRIVATE_FRIEND(
class PdfParser);
48 PODOFO_PRIVATE_FRIEND(
class PdfXRef);
125 std::string_view GetDataTypeString()
const;
131 bool IsNumber()
const;
136 bool IsRealStrict()
const;
139 bool IsNumberOrReal()
const;
142 bool IsString()
const;
148 bool IsArray()
const;
151 bool IsDictionary()
const;
154 bool IsRawData()
const;
160 bool IsReference()
const;
170 bool GetBool()
const;
171 bool TryGetBool(
bool& value)
const;
177 int64_t GetNumberLenient()
const;
178 bool TryGetNumberLenient(
int64_t& value)
const;
185 bool TryGetNumber(
int64_t& value)
const;
191 double GetReal()
const;
192 bool TryGetReal(
double& value)
const;
198 double GetRealStrict()
const;
199 bool TryGetRealStrict(
double& value)
const;
207 const PdfName& GetName()
const;
237 void SetBool(
bool b);
251 void SetReal(
double d);
269 void ForceCreateStream();
304 virtual bool TryUnload();
310 bool HasStream()
const;
312 bool IsIndirect()
const;
357 inline bool IsDirty()
const {
return m_IsDirty; }
378 inline bool IsDelayedLoadStreamDone()
const {
return m_IsDelayedLoadStreamDone; }
380 const PdfObjectStream* GetStream()
const;
381 PdfObjectStream* GetStream();
384 PdfObject(PdfVariant&& var,
const PdfReference& indirectReference,
bool isDirty);
386 PdfObject(PdfArray* arr);
395 void DelayedLoad()
const;
410 virtual void delayedLoad();
412 void DelayedLoadStream()
const;
414 virtual void delayedLoadStream();
417 virtual bool removeStream();
419 virtual bool HasStreamToParse()
const;
432 void SetDocument(PdfDocument* document);
434 void SetVariantOwner();
438 PdfObjectStream& getOrCreateStream();
440 void forceCreateStream();
442 PdfObjectStream* getStream();
444 void EnableDelayedLoadingStream();
446 void MakeDelayedLoadingStreamDone();
448 inline void SetIndirectReference(
const PdfReference& reference) { m_IndirectReference = reference; }
457 void EnableDelayedLoading();
461 virtual void SetRevised();
464 void DelayedLoad(
bool throwOnError)
const;
465 void DelayedLoadStream(
bool throwOnError)
const;
468 PdfVariant& GetVariantUnsafe() {
return m_Variant; }
469 const PdfReference& GetReferenceUnsafe()
const {
return m_Variant.GetReferenceUnsafe(); }
470 const PdfDictionary& GetDictionaryUnsafe()
const {
return m_Variant.GetDictionaryUnsafe(); }
471 const PdfArray& GetArrayUnsafe()
const {
return m_Variant.GetArrayUnsafe(); }
472 PdfDictionary& GetDictionaryUnsafe() {
return m_Variant.GetDictionaryUnsafe(); }
473 PdfArray& GetArrayUnsafe() {
return m_Variant.GetArrayUnsafe(); }
474 void WriteFinal(OutputStream& stream, PdfWriteFlags writeMode,
475 const PdfStatefulEncrypt* encrypt, charbuff& buffer);
478 void SetNumberNoDirtySet(int64_t l);
482 void WriteHeader(OutputStream& stream, PdfWriteFlags writeMode, charbuff& buffer)
const;
485 bool IsImmutable()
const {
return m_IsImmutable; }
488 void AssignNoDirtySet(PdfObject&& rhs);
489 void AssignNoDirtySet(PdfVariant&& rhs);
490 void AssignNoDirtySet(
const PdfObject& rhs);
492 void SetParent(PdfDataContainer& parent);
495 void write(OutputStream& stream,
bool skipLengthFix,
496 PdfWriteFlags writeMode,
const PdfStatefulEncrypt* encrypt, charbuff& buffer)
const;
498 void assertMutable()
const;
500 void assign(
const PdfObject& rhs);
502 void moveFrom(PdfObject&& rhs)
noexcept;
512 PdfObject(T*) =
delete;
514 void copyStreamFrom(
const PdfObject& obj);
520 PdfVariant m_Variant;
523 PdfReference m_IndirectReference;
524 PdfDocument* m_Document;
525 PdfDataContainer* m_Parent;
526 std::unique_ptr<PdfObjectStream> m_Stream;
529 mutable bool m_IsDelayedLoadDone;
530 mutable bool m_IsDelayedLoadStreamDone;
536 template <
typename T>
572 return obj.GetBool();
575 static bool Get(
const PdfObject& obj,
bool fallback)
578 if (obj.TryGetBool(ret))
584 static bool TryGet(
const PdfObject& obj,
bool& value)
586 return obj.TryGetBool(value);
591 struct ObjectAdapter<int64_t>
593 using TRet = int64_t;
595 static int64_t Get(
const PdfObject& obj)
597 return obj.GetNumber();
600 static int64_t Get(
const PdfObject& obj, int64_t fallback)
603 if (obj.TryGetNumber(ret))
609 static bool TryGet(
const PdfObject& obj, int64_t& value)
611 return obj.TryGetNumber(value);
616 struct ObjectAdapter<double>
620 static double Get(
const PdfObject& obj)
622 return obj.GetReal();
625 static double Get(
const PdfObject& obj,
double fallback)
628 if (obj.TryGetReal(ret))
634 static bool TryGet(
const PdfObject& obj,
double& value)
636 return obj.TryGetReal(value);
641 struct ObjectAdapter<PdfReference>
643 using TRet = PdfReference;
645 static PdfReference Get(
const PdfObject& obj)
647 return obj.GetReference();
650 static PdfReference Get(
const PdfObject& obj,
const PdfReference& fallback)
653 if (obj.TryGetReference(ret))
659 static bool TryGet(
const PdfObject& obj, PdfReference& value)
661 return obj.TryGetReference(value);
666 struct ObjectAdapter<PdfName>
668 using TRet =
const PdfName&;
670 static const PdfName& Get(
const PdfObject& obj)
672 return obj.GetName();
675 static const PdfName& Get(
const PdfObject& obj,
const PdfName& fallback)
678 if (obj.TryGetName(ret))
684 static bool TryGet(
const PdfObject& obj, PdfName& value)
686 return obj.TryGetName(value);
691 struct ObjectAdapter<const PdfName*>
693 using TRet =
const PdfName*;
695 static const PdfName* Get(
const PdfObject& obj)
698 (void)obj.TryGetName(ret);
702 static const PdfName* Get(
const PdfObject& obj,
const PdfName* fallback)
705 if (obj.TryGetName(ret))
711 static bool TryGet(
const PdfObject& obj,
const PdfName*& value)
713 return obj.TryGetName(value);
718 struct ObjectAdapter<PdfString>
720 using TRet =
const PdfString&;
722 static const PdfString& Get(
const PdfObject& obj)
724 return obj.GetString();
727 static const PdfString& Get(
const PdfObject& obj,
const PdfString& fallback)
729 const PdfString* ret;
730 if (obj.TryGetString(ret))
736 static bool TryGet(
const PdfObject& obj, PdfString& value)
738 return obj.TryGetString(value);
743 struct ObjectAdapter<const PdfString*>
745 using TRet =
const PdfString*;
747 static const PdfString* Get(PdfObject& obj)
749 const PdfString* ret;
750 (void)obj.TryGetString(ret);
754 static const PdfString* Get(
const PdfObject& obj,
const PdfString* fallback)
756 const PdfString* ret;
757 if (obj.TryGetString(ret))
763 static bool TryGet(
const PdfObject& obj,
const PdfString*& value)
765 return obj.TryGetString(value);
770 struct ObjectAdapter<PdfDictionary*>
772 using TRet = PdfDictionary*;
774 static PdfDictionary* Get(PdfObject& obj)
777 (void)obj.TryGetDictionary(ret);
781 static PdfDictionary* Get(PdfObject& obj, PdfDictionary* fallback)
784 if (obj.TryGetDictionary(ret))
790 static bool TryGet(PdfObject& obj, PdfDictionary*& value)
792 return obj.TryGetDictionary(value);
797 struct ObjectAdapter<const PdfDictionary*>
799 using TRet =
const PdfDictionary*;
801 static const PdfDictionary* Get(
const PdfObject& obj)
803 const PdfDictionary* ret;
804 (void)obj.TryGetDictionary(ret);
808 static const PdfDictionary* Get(
const PdfObject& obj,
const PdfDictionary* fallback)
810 const PdfDictionary* ret;
811 if (obj.TryGetDictionary(ret))
817 static bool TryGet(
const PdfObject& obj,
const PdfDictionary*& value)
819 return obj.TryGetDictionary(value);
824 struct ObjectAdapter<PdfDictionary>
826 using TRet = PdfDictionary&;
828 static PdfDictionary& Get(PdfObject& obj)
830 return obj.GetDictionary();
833 static PdfDictionary& Get(PdfObject& obj, PdfDictionary& fallback)
836 if (obj.TryGetDictionary(ret))
842 static bool TryGet(
const PdfObject& obj, PdfDictionary& value)
844 return obj.TryGetDictionary(value);
849 struct ObjectAdapter<PdfArray*>
851 using TRet = PdfArray*;
853 static PdfArray* Get(PdfObject& obj)
856 (void)obj.TryGetArray(ret);
860 static PdfArray* Get(PdfObject& obj, PdfArray* fallback)
863 if (obj.TryGetArray(ret))
869 static bool TryGet(PdfObject& obj, PdfArray*& value)
871 return obj.TryGetArray(value);
876 struct ObjectAdapter<const PdfArray*>
878 using TRet =
const PdfArray*;
880 static const PdfArray* Get(
const PdfObject& obj)
883 (void)obj.TryGetArray(ret);
887 static const PdfArray* Get(PdfObject& obj,
const PdfArray* fallback)
890 if (obj.TryGetArray(ret))
896 static bool TryGet(
const PdfObject& obj,
const PdfArray*& value)
898 return obj.TryGetArray(value);
903 struct ObjectAdapter<PdfArray>
905 using TRet = PdfArray&;
907 static PdfArray& Get(PdfObject& obj)
909 return obj.GetArray();
912 static PdfArray& Get(PdfObject& obj, PdfArray& fallback)
915 if (obj.TryGetArray(ret))
921 static bool TryGet(
const PdfObject& obj, PdfArray& value)
923 return obj.TryGetArray(value);
930 struct PODOFO_API PdfObjectInequality final
932 using is_transparent = std::true_type;
934 bool operator()(
const PdfObject* lhs,
const PdfObject* rhs)
const
936 return lhs->GetIndirectReference() < rhs->GetIndirectReference();
938 bool operator()(
const PdfObject* lhs,
const PdfReference& rhs)
const
940 return lhs->GetIndirectReference() < rhs;
942 bool operator()(
const PdfReference& lhs,
const PdfObject* rhs)
const
944 return lhs < rhs->GetIndirectReference();
946 bool operator()(
const PdfObject& lhs,
const PdfObject& rhs)
const
948 return lhs.GetIndirectReference() < rhs.GetIndirectReference();
950 bool operator()(
const PdfObject& lhs,
const PdfReference& rhs)
const
952 return lhs.GetIndirectReference() < rhs;
954 bool operator()(
const PdfReference& lhs,
const PdfObject& rhs)
const
956 return lhs < rhs.GetIndirectReference();
An interface for writing blocks of data to a data source.
Definition OutputStream.h:15
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:76
A PdfDataProvider object with a PdfObject owner, specialized in holding objects.
Definition PdfDataContainer.h:18
The PDF dictionary data type of PoDoFo (inherits from PdfDataContainer, the base class for such repre...
Definition PdfDictionary.h:77
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:108
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition PdfIndirectObjectList.h:34
This class represents a PdfName.
Definition PdfName.h:21
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition PdfObjectStream.h:82
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
bool IsDelayedLoadDone() const
Returns true if delayed loading is disabled, or if it is enabled and loading has completed.
Definition PdfObject.h:376
PdfDocument * GetDocument() const
Get the document of this object.
Definition PdfObject.h:361
PdfObject(std::nullptr_t)
Create a "null" PDF object.
bool IsDirty() const
The dirty flag is set if this variant has been modified after construction.
Definition PdfObject.h:357
const PdfReference & GetIndirectReference() const
Get an indirect reference to this object.
Definition PdfObject.h:369
A reference is a pointer to a object in the PDF file of the form "4 0 R", where 4 is the object numbe...
Definition PdfReference.h:20
A string that can be written to a PDF document.
Definition PdfString.h:21
A simple tokenizer for PDF files and PDF content streams.
Definition PdfTokenizer.h:47
A variant data type which supports all data types supported by the PDF standard.
Definition PdfVariant.h:29
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfDataType
Every PDF datatype that can occur in a PDF file is referenced by an own enum (e.g.
Definition PdfDeclarations.h:152
@ Null
The null datatype is always null.
PdfWriteFlags
Specify additional options for writing the PDF.
Definition PdfDeclarations.h:136
Templatized object type getter helper.
Definition PdfObject.h:538