10#include "PdfIndirectObjectList.h"
11#include "PdfAcroForm.h"
12#include "PdfFontManager.h"
13#include "PdfMetadata.h"
14#include "PdfPageCollection.h"
15#include "PdfNameTrees.h"
16#include "PdfXObjectForm.h"
18#include "PdfColorSpace.h"
19#include "PdfPattern.h"
20#include "PdfFunction.h"
22#include "PdfOutlines.h"
23#include "PdfExtension.h"
32template <
typename TField>
33class PdfDocumentFieldIterableBase final
35 friend class PdfDocument;
38 PdfDocumentFieldIterableBase()
42 PdfDocumentFieldIterableBase(PdfDocument& doc)
48 friend class PdfDocumentFieldIterableBase;
50 using difference_type = void;
51 using value_type = TField*;
53 using reference = void;
54 using iterator_category = std::forward_iterator_tag;
58 Iterator(PdfDocument& doc);
60 Iterator(
const Iterator&) =
default;
61 Iterator& operator=(
const Iterator&) =
default;
62 bool operator==(
const Iterator& rhs)
const;
63 bool operator!=(
const Iterator& rhs)
const;
64 Iterator& operator++();
65 Iterator operator++(
int);
66 value_type operator*() {
return m_Field; }
67 value_type operator->() {
return m_Field; }
70 void stepIntoPageOrForm(PdfPageCollection& pages);
71 bool stepIntoPageAnnot(PdfAnnotationCollection& annots);
72 void stepIntoFormField(PdfAcroForm& form);
76 PdfAnnotationCollection::iterator m_pageAnnotIterator;
77 PdfAcroForm::iterator m_acroFormIterator;
79 std::unordered_set<PdfReference> m_visitedObjs;
83 Iterator begin()
const;
90using PdfDocumentFieldIterable = PdfDocumentFieldIterableBase<PdfField>;
91using PdfDocumentConstFieldIterable = PdfDocumentFieldIterableBase<const PdfField>;
109 friend class PdfMetadata;
110 friend class PdfXObjectForm;
142 void CollectGarbage();
145 std::unique_ptr<PdfImage> CreateImage();
147 std::unique_ptr<PdfXObjectForm> CreateXObjectForm(
const Rect&
rect);
149 std::unique_ptr<PdfDestination> CreateDestination();
155 std::unique_ptr<PdfUncolouredTilingPattern> CreateTilingPattern(std::shared_ptr<PdfUncolouredTilingPatternDefinition>
definition);
157 std::unique_ptr<PdfColouredTilingPattern> CreateTilingPattern(std::shared_ptr<PdfColouredTilingPatternDefinition>
definition);
165 template <
typename Taction>
166 std::unique_ptr<Taction> CreateAction();
170 std::unique_ptr<PdfFileSpec> CreateFileSpec();
178 bool IsPrintAllowed()
const;
186 bool IsEditAllowed()
const;
194 bool IsCopyAllowed()
const;
202 bool IsEditNotesAllowed()
const;
210 bool IsFillAndSignAllowed()
const;
218 bool IsAccessibilityAllowed()
const;
226 bool IsDocAssemblyAllowed()
const;
234 bool IsHighPrintAllowed()
const;
245 bool HasPdfExtension(
const std::string_view&
ns,
int64_t level)
const;
250 void RemovePdfExtension(
const std::string_view&
ns,
int64_t level);
254 std::vector<PdfExtension> GetPdfExtensions()
const;
256 PdfAcroForm& MustGetAcroForm();
258 const PdfAcroForm& MustGetAcroForm()
const;
287 virtual const PdfEncrypt* GetEncrypt()
const = 0;
290 bool IsEncrypted()
const;
330 const PdfInfo* GetInfo()
const;
332 PdfMetadata& GetMetadata() {
return m_Metadata; }
334 const PdfMetadata& GetMetadata()
const {
return m_Metadata; }
348 PdfAcroForm* GetAcroForm() {
return m_AcroForm.get(); }
350 const PdfAcroForm* GetAcroForm()
const {
return m_AcroForm.get(); }
352 PdfNameTrees* GetNames() {
return m_NameTrees.get(); }
354 const PdfNameTrees* GetNames()
const {
return m_NameTrees.get(); }
356 PdfOutlines* GetOutlines();
358 const PdfOutlines* GetOutlines()
const;
360 PdfFontManager& GetFonts() {
return m_FontManager; }
368 void SetTrailer(std::unique_ptr<PdfObject> obj);
373 virtual void reset();
378 virtual void clear();
421 void lazyLoadOutlines();
429 PdfMetadata m_Metadata;
431 bool m_InfoLazyLoaded;
432 bool m_OutlinesLazyLoaded;
433 std::unique_ptr<PdfObject> m_TrailerObj;
434 std::unique_ptr<PdfTrailer> m_Trailer;
435 std::unique_ptr<PdfCatalog> m_Catalog;
436 std::unique_ptr<PdfInfo> m_Info;
437 std::unique_ptr<PdfPageCollection> m_Pages;
438 std::unique_ptr<PdfAcroForm> m_AcroForm;
439 std::unique_ptr<PdfOutlines> m_Outlines;
440 std::unique_ptr<PdfNameTrees> m_NameTrees;
443template<
typename TAction>
444std::unique_ptr<TAction> PdfDocument::CreateAction()
446 std::unique_ptr<TAction>
ret;
447 createAction(PdfAction::GetActionType<TAction>(),
reinterpret_cast<std::unique_ptr<PdfAction>&
>(
ret));
451template<
typename TField>
452typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::begin()
const
454 if (m_doc ==
nullptr)
457 return Iterator(*m_doc);
460template<
typename TField>
461typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::end()
const
466template<
typename TField>
467PdfDocumentFieldIterableBase<TField>::Iterator::Iterator()
468 : m_doc(nullptr), m_pageIndex(0), m_Field(nullptr)
472template<
typename TField>
473PdfDocumentFieldIterableBase<TField>::Iterator::Iterator(PdfDocument& doc)
474 : m_doc(&doc), m_pageIndex(0), m_Field(nullptr)
476 stepIntoPageOrForm(doc.GetPages());
479template<
typename TField>
480bool PdfDocumentFieldIterableBase<TField>::Iterator::operator==(
const Iterator& rhs)
const
482 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
485 return m_doc == rhs.m_doc && m_pageIndex == rhs.m_pageIndex && m_pageAnnotIterator == rhs.m_pageAnnotIterator && m_acroFormIterator == rhs.m_acroFormIterator;
488template<
typename TField>
489bool PdfDocumentFieldIterableBase<TField>::Iterator::operator!=(
const Iterator& rhs)
const
491 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
494 return m_doc != rhs.m_doc || m_pageIndex != rhs.m_pageIndex || m_pageAnnotIterator != rhs.m_pageAnnotIterator || m_acroFormIterator != rhs.m_acroFormIterator;
497template<
typename TField>
498typename PdfDocumentFieldIterableBase<TField>::Iterator& PdfDocumentFieldIterableBase<TField>::Iterator::operator++()
504template<
typename TField>
505typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::Iterator::operator++(
int)
512template<
typename TField>
513void PdfDocumentFieldIterableBase<TField>::Iterator::increment()
515 if (m_doc ==
nullptr)
518 auto& pages = m_doc->GetPages();
519 if (m_pageIndex < pages.GetCount())
521 m_pageAnnotIterator++;
522 if (stepIntoPageAnnot(pages.GetPageAt(m_pageIndex).GetAnnotations()))
526 stepIntoPageOrForm(pages);
530 m_acroFormIterator++;
531 stepIntoFormField(m_doc->MustGetAcroForm());
536template<
typename TField>
537void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageOrForm(PdfPageCollection& pages)
541 if (m_pageIndex >= pages.GetCount())
544 auto& annots = pages.GetPageAt(m_pageIndex).GetAnnotations();
545 m_pageAnnotIterator = annots.begin();
546 if (stepIntoPageAnnot(annots))
552 auto form = m_doc->GetAcroForm();
555 m_acroFormIterator = form->begin();
556 stepIntoFormField(*form);
563 m_visitedObjs.clear();
568template<
typename TField>
569bool PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageAnnot(PdfAnnotationCollection& annots)
573 if (m_pageAnnotIterator == annots.end())
576 auto& annot = **m_pageAnnotIterator;
577 PdfField* field =
nullptr;
578 if (annot.GetType() == PdfAnnotationType::Widget &&
579 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
580 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
583 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
587 m_pageAnnotIterator++;
595template<
typename TField>
596void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoFormField(PdfAcroForm& form)
600 if (m_acroFormIterator == form.end())
603 auto& field = **m_acroFormIterator;
604 if (field.GetChildren().GetCount() == 0
605 && m_visitedObjs.find(field.GetObject().GetIndirectReference()) == m_visitedObjs.end())
608 m_visitedObjs.insert(field.GetObject().GetIndirectReference());
612 m_acroFormIterator++;
618 m_visitedObjs.clear();
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:108
PdfPageCollection & GetPages()
Get access to the page tree.
Definition PdfDocument.h:307
const PdfPageCollection & GetPages() const
Get access to the page tree.
Definition PdfDocument.h:311
virtual PdfVersion GetPdfVersion() const =0
Get the PDF version of the document.
const PdfTrailer & GetTrailer() const
Get access to the internal trailer dictionary or root object.
Definition PdfDocument.h:323
virtual bool HasOwnerPermissions() const =0
Checks if document has been opened with full owner privileges.
PdfTrailer & GetTrailer()
Get access to the internal trailer dictionary or root object.
Definition PdfDocument.h:317
virtual void SetPdfVersion(PdfVersion version)=0
Get the PDF version of the document.
PdfCatalog & GetCatalog()
Get access to the internal Catalog dictionary or root object.
Definition PdfDocument.h:297
PdfIndirectObjectList & GetObjects()
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:340
const PdfIndirectObjectList & GetObjects() const
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:346
const PdfCatalog & GetCatalog() const
Get access to the internal Catalog dictionary or root object.
Definition PdfDocument.h:303
A class that is used to encrypt a PDF file and set document permissions on the PDF file.
Definition PdfEncrypt.h:111
PdfExtension is a simple class that describes a vendor-specific extension to the official specificati...
Definition PdfExtension.h:15
This class assists PdfDocument with caching font information.
Definition PdfFontManager.h:50
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition PdfIndirectObjectList.h:28
This class provides access to the documents info dictionary, which provides information about the PDF...
Definition PdfInfo.h:18
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition PdfMemDocument.h:35
Interface to access names trees in the document.
Definition PdfNameTrees.h:18
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
The main PDF outlines dictionary.
Definition PdfOutlines.h:175
Class for managing the tree of Pages in a PDF document Don't use this class directly.
Definition PdfPageCollection.h:21
PdfPage is one page in the pdf document.
Definition PdfPage.h:133
PdfStreamedDocument is the preferred class for creating new PDF documents.
Definition PdfStreamedDocument.h:47
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:17
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
std::shared_ptr< const PdfColorSpaceFilter > PdfColorSpaceFilterPtr
Convenience alias for a constant PdfColorSpaceFilter shared ptr.
Definition PdfColorSpaceFilter.h:71
std::shared_ptr< const PdfShadingDefinition > PdfShadingDefinitionPtr
Convenience alias for a constant PdfShadingDefinition shared ptr.
Definition PdfPatternDefinition.h:163
PdfAcroFormDefaulAppearance
Definition PdfAcroForm.h:15
std::shared_ptr< const PdfShadingPatternDefinition > PdfShadingPatternDefinitionPtr
Convenience alias for a constant PdfShadingPatternDefinition shared ptr.
Definition PdfPatternDefinition.h:391
std::shared_ptr< const PdfExtGStateDefinition > PdfExtGStateDefinitionPtr
Convenience alias for a constant PdfExtGStateDefinition shared ptr.
Definition PdfExtGStateDefinition.h:30
PdfActionType
The type of the action.
Definition PdfAction.h:25
PdfVersion
Enum to identify different versions of the PDF file format.
Definition PdfDeclarations.h:61
std::shared_ptr< const PdfFunctionDefinition > PdfFunctionDefinitionPtr
Convenience alias for a constant PdfFunction shared ptr.
Definition PdfFunctionDefinition.h:54