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;
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;
293 bool IsStrictParsing()
const {
return m_IsStrictParsing; }
332 const PdfInfo* GetInfo()
const;
334 PdfMetadata& GetMetadata() {
return m_Metadata; }
336 const PdfMetadata& GetMetadata()
const {
return m_Metadata; }
350 PdfAcroForm* GetAcroForm() {
return m_AcroForm.get(); }
352 const PdfAcroForm* GetAcroForm()
const {
return m_AcroForm.get(); }
354 PdfNameTrees* GetNames() {
return m_NameTrees.get(); }
356 const PdfNameTrees* GetNames()
const {
return m_NameTrees.get(); }
358 PdfOutlines* GetOutlines();
360 const PdfOutlines* GetOutlines()
const;
362 PdfFontManager& GetFonts() {
return m_FontManager; }
366 void SetEntryPoints(std::unique_ptr<PdfObject>&& trailer, PdfObject& catalog);
368 void SetStrictParsing(
bool value);
373 virtual void reset();
378 virtual void clear();
415 void lazyLoadOutlines();
423 PdfMetadata m_Metadata;
425 bool m_IsStrictParsing;
426 bool m_InfoLazyLoaded;
427 bool m_OutlinesLazyLoaded;
428 std::unique_ptr<PdfObject> m_TrailerObj;
429 std::unique_ptr<PdfTrailer> m_Trailer;
430 std::unique_ptr<PdfCatalog> m_Catalog;
431 std::unique_ptr<PdfInfo> m_Info;
432 std::unique_ptr<PdfPageCollection> m_Pages;
433 std::unique_ptr<PdfAcroForm> m_AcroForm;
434 std::unique_ptr<PdfOutlines> m_Outlines;
435 std::unique_ptr<PdfNameTrees> m_NameTrees;
438template<
typename TAction>
439std::unique_ptr<TAction> PdfDocument::CreateAction()
441 std::unique_ptr<TAction>
ret;
442 createAction(PdfAction::GetActionType<TAction>(),
reinterpret_cast<std::unique_ptr<PdfAction>&
>(
ret));
446template<
typename TField>
447typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::begin()
const
449 if (m_doc ==
nullptr)
452 return Iterator(*m_doc);
455template<
typename TField>
456typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::end()
const
461template<
typename TField>
462PdfDocumentFieldIterableBase<TField>::Iterator::Iterator()
463 : m_doc(nullptr), m_pageIndex(0), m_Field(nullptr)
467template<
typename TField>
468PdfDocumentFieldIterableBase<TField>::Iterator::Iterator(PdfDocument& doc)
469 : m_doc(&doc), m_pageIndex(0), m_Field(nullptr)
471 stepIntoPageOrForm(doc.GetPages());
474template<
typename TField>
475bool PdfDocumentFieldIterableBase<TField>::Iterator::operator==(
const Iterator& rhs)
const
477 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
480 return m_doc == rhs.m_doc && m_pageIndex == rhs.m_pageIndex && m_pageAnnotIterator == rhs.m_pageAnnotIterator && m_acroFormIterator == rhs.m_acroFormIterator;
483template<
typename TField>
484bool PdfDocumentFieldIterableBase<TField>::Iterator::operator!=(
const Iterator& rhs)
const
486 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
489 return m_doc != rhs.m_doc || m_pageIndex != rhs.m_pageIndex || m_pageAnnotIterator != rhs.m_pageAnnotIterator || m_acroFormIterator != rhs.m_acroFormIterator;
492template<
typename TField>
493typename PdfDocumentFieldIterableBase<TField>::Iterator& PdfDocumentFieldIterableBase<TField>::Iterator::operator++()
499template<
typename TField>
500typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::Iterator::operator++(
int)
507template<
typename TField>
508void PdfDocumentFieldIterableBase<TField>::Iterator::increment()
510 if (m_doc ==
nullptr)
513 auto& pages = m_doc->GetPages();
514 if (m_pageIndex < pages.GetCount())
516 m_pageAnnotIterator++;
517 if (stepIntoPageAnnot(pages.GetPageAt(m_pageIndex).GetAnnotations()))
521 stepIntoPageOrForm(pages);
525 m_acroFormIterator++;
526 stepIntoFormField(m_doc->MustGetAcroForm());
531template<
typename TField>
532void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageOrForm(PdfPageCollection& pages)
536 if (m_pageIndex >= pages.GetCount())
539 auto& annots = pages.GetPageAt(m_pageIndex).GetAnnotations();
540 m_pageAnnotIterator = annots.begin();
541 if (stepIntoPageAnnot(annots))
547 auto form = m_doc->GetAcroForm();
550 m_acroFormIterator = form->begin();
551 stepIntoFormField(*form);
558 m_visitedObjs.clear();
563template<
typename TField>
564bool PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageAnnot(PdfAnnotationCollection& annots)
568 if (m_pageAnnotIterator == annots.end())
571 auto& annot = **m_pageAnnotIterator;
572 PdfField* field =
nullptr;
573 if (annot.GetType() == PdfAnnotationType::Widget &&
574 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
575 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
578 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
582 m_pageAnnotIterator++;
590template<
typename TField>
591void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoFormField(PdfAcroForm& form)
595 if (m_acroFormIterator == form.end())
598 auto& field = **m_acroFormIterator;
599 if (field.GetChildren().GetCount() == 0
600 && m_visitedObjs.find(field.GetObject().GetIndirectReference()) == m_visitedObjs.end())
603 m_visitedObjs.insert(field.GetObject().GetIndirectReference());
607 m_acroFormIterator++;
613 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:309
const PdfPageCollection & GetPages() const
Get access to the page tree.
Definition PdfDocument.h:313
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:325
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:319
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:299
PdfIndirectObjectList & GetObjects()
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:342
const PdfIndirectObjectList & GetObjects() const
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:348
const PdfCatalog & GetCatalog() const
Get access to the internal Catalog dictionary or root object.
Definition PdfDocument.h:305
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:34
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
A PDF outline item has a title and a destination.
Definition PdfOutlines.h:33
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:37
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
PdfGarbageCollectionFlags
Definition PdfIndirectObjectList.h:17
std::shared_ptr< const PdfShadingDefinition > PdfShadingDefinitionPtr
Convenience alias for a constant PdfShadingDefinition shared ptr.
Definition PdfPatternDefinition.h:180
PdfAcroFormDefaulAppearance
Definition PdfAcroForm.h:15
std::shared_ptr< const PdfShadingPatternDefinition > PdfShadingPatternDefinitionPtr
Convenience alias for a constant PdfShadingPatternDefinition shared ptr.
Definition PdfPatternDefinition.h:409
PdfFillFormFlags
Definition PdfXObjectForm.h:18
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