10#include "PdfTrailer.h"
11#include "PdfCatalog.h"
12#include "PdfIndirectObjectList.h"
13#include "PdfAcroForm.h"
14#include "PdfFontManager.h"
15#include "PdfMetadata.h"
16#include "PdfPageCollection.h"
17#include "PdfNameTrees.h"
18#include "PdfXObjectForm.h"
20#include "PdfColorSpace.h"
21#include "PdfPattern.h"
22#include "PdfFunction.h"
24#include "PdfOutlines.h"
25#include "PdfExtension.h"
34template <
typename TField>
35class PdfDocumentFieldIterableBase final
37 friend class PdfDocument;
40 PdfDocumentFieldIterableBase()
44 PdfDocumentFieldIterableBase(PdfDocument& doc)
50 friend class PdfDocumentFieldIterableBase;
52 using difference_type = void;
53 using value_type = TField*;
55 using reference = void;
56 using iterator_category = std::forward_iterator_tag;
60 Iterator(PdfDocument& doc);
62 Iterator(
const Iterator&) =
default;
63 Iterator& operator=(
const Iterator&) =
default;
64 bool operator==(
const Iterator& rhs)
const;
65 bool operator!=(
const Iterator& rhs)
const;
66 Iterator& operator++();
67 Iterator operator++(
int);
68 value_type operator*() {
return m_Field; }
69 value_type operator->() {
return m_Field; }
72 void stepIntoPageOrForm(PdfPageCollection& pages);
73 bool stepIntoPageAnnot(PdfAnnotationCollection& annots);
74 void stepIntoFormField(PdfAcroForm& form);
78 PdfAnnotationCollection::iterator m_pageAnnotIterator;
79 PdfAcroForm::iterator m_acroFormIterator;
81 std::unordered_set<PdfReference> m_visitedObjs;
85 Iterator begin()
const;
92using PdfDocumentFieldIterable = PdfDocumentFieldIterableBase<PdfField>;
93using PdfDocumentConstFieldIterable = PdfDocumentFieldIterableBase<const PdfField>;
112 friend class PdfMetadata;
113 friend class PdfXObjectForm;
151 void CollectGarbage();
155 std::unique_ptr<PdfImage> CreateImage();
157 std::unique_ptr<PdfXObjectForm> CreateXObjectForm(
const Rect&
rect);
159 std::unique_ptr<PdfDestination> CreateDestination();
165 std::unique_ptr<PdfUncolouredTilingPattern> CreateTilingPattern(std::shared_ptr<PdfUncolouredTilingPatternDefinition>
definition);
167 std::unique_ptr<PdfColouredTilingPattern> CreateTilingPattern(std::shared_ptr<PdfColouredTilingPatternDefinition>
definition);
175 template <
typename Taction>
176 std::unique_ptr<Taction> CreateAction();
180 std::unique_ptr<PdfFileSpec> CreateFileSpec();
189 bool IsPrintAllowed()
const;
198 bool IsEditAllowed()
const;
207 bool IsCopyAllowed()
const;
216 bool IsEditNotesAllowed()
const;
225 bool IsFillAndSignAllowed()
const;
234 bool IsAccessibilityAllowed()
const;
243 bool IsDocAssemblyAllowed()
const;
252 bool IsHighPrintAllowed()
const;
264 bool HasPdfExtension(
const std::string_view&
ns,
int64_t level)
const;
270 void RemovePdfExtension(
const std::string_view&
ns,
int64_t level);
276 std::vector<PdfExtension> GetPdfExtensions()
const;
278 PdfAcroForm& MustGetAcroForm();
280 const PdfAcroForm& MustGetAcroForm()
const;
313 virtual const PdfEncrypt* GetEncrypt()
const = 0;
318 bool IsEncrypted()
const;
367 PdfMetadata& GetMetadata() {
return m_Metadata; }
369 const PdfMetadata& GetMetadata()
const {
return m_Metadata; }
385 PdfAcroForm* GetAcroForm() {
return m_AcroForm.get(); }
387 const PdfAcroForm* GetAcroForm()
const {
return m_AcroForm.get(); }
389 PdfNameTrees* GetNames() {
return m_NameTrees.get(); }
391 const PdfNameTrees* GetNames()
const {
return m_NameTrees.get(); }
393 PdfOutlines* GetOutlines();
395 const PdfOutlines* GetOutlines()
const;
397 PdfFontManager& GetFonts() {
return m_FontManager; }
406 void SetTrailer(std::unique_ptr<PdfObject> obj);
412 virtual void reset();
418 virtual void clear();
472 PdfMetadata m_Metadata;
474 std::unique_ptr<PdfObject> m_TrailerObj;
475 std::unique_ptr<PdfTrailer> m_Trailer;
476 std::unique_ptr<PdfCatalog> m_Catalog;
477 std::unique_ptr<PdfInfo> m_Info;
478 std::unique_ptr<PdfPageCollection> m_Pages;
479 std::unique_ptr<PdfAcroForm> m_AcroForm;
481 std::unique_ptr<PdfNameTrees> m_NameTrees;
484template<
typename TAction>
485std::unique_ptr<TAction> PdfDocument::CreateAction()
487 std::unique_ptr<TAction>
ret;
488 createAction(PdfAction::GetActionType<TAction>(),
reinterpret_cast<std::unique_ptr<PdfAction>&
>(
ret));
492template<
typename TField>
493typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::begin()
const
495 if (m_doc ==
nullptr)
498 return Iterator(*m_doc);
501template<
typename TField>
502typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::end()
const
507template<
typename TField>
508PdfDocumentFieldIterableBase<TField>::Iterator::Iterator()
509 : m_doc(nullptr), m_pageIndex(0), m_Field(nullptr)
513template<
typename TField>
514PdfDocumentFieldIterableBase<TField>::Iterator::Iterator(PdfDocument& doc)
515 : m_doc(&doc), m_pageIndex(0), m_Field(nullptr)
517 stepIntoPageOrForm(doc.GetPages());
520template<
typename TField>
521bool PdfDocumentFieldIterableBase<TField>::Iterator::operator==(
const Iterator& rhs)
const
523 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
526 return m_doc == rhs.m_doc && m_pageIndex == rhs.m_pageIndex && m_pageAnnotIterator == rhs.m_pageAnnotIterator && m_acroFormIterator == rhs.m_acroFormIterator;
529template<
typename TField>
530bool PdfDocumentFieldIterableBase<TField>::Iterator::operator!=(
const Iterator& rhs)
const
532 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
535 return m_doc != rhs.m_doc || m_pageIndex != rhs.m_pageIndex || m_pageAnnotIterator != rhs.m_pageAnnotIterator || m_acroFormIterator != rhs.m_acroFormIterator;
538template<
typename TField>
539typename PdfDocumentFieldIterableBase<TField>::Iterator& PdfDocumentFieldIterableBase<TField>::Iterator::operator++()
545template<
typename TField>
546typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::Iterator::operator++(
int)
553template<
typename TField>
554void PdfDocumentFieldIterableBase<TField>::Iterator::increment()
556 if (m_doc ==
nullptr)
559 auto& pages = m_doc->GetPages();
560 if (m_pageIndex < pages.GetCount())
562 m_pageAnnotIterator++;
563 if (stepIntoPageAnnot(pages.GetPageAt(m_pageIndex).GetAnnotations()))
567 stepIntoPageOrForm(pages);
571 m_acroFormIterator++;
572 stepIntoFormField(m_doc->MustGetAcroForm());
577template<
typename TField>
578void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageOrForm(PdfPageCollection& pages)
582 if (m_pageIndex >= pages.GetCount())
585 auto& annots = pages.GetPageAt(m_pageIndex).GetAnnotations();
586 m_pageAnnotIterator = annots.begin();
587 if (stepIntoPageAnnot(annots))
593 auto form = m_doc->GetAcroForm();
596 m_acroFormIterator = form->begin();
597 stepIntoFormField(*form);
604 m_visitedObjs.clear();
609template<
typename TField>
610bool PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageAnnot(PdfAnnotationCollection& annots)
614 if (m_pageAnnotIterator == annots.end())
617 auto& annot = **m_pageAnnotIterator;
618 PdfField* field =
nullptr;
619 if (annot.GetType() == PdfAnnotationType::Widget &&
620 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
621 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
624 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
628 m_pageAnnotIterator++;
636template<
typename TField>
637void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoFormField(PdfAcroForm& form)
641 if (m_acroFormIterator == form.end())
644 auto& field = **m_acroFormIterator;
645 if (field.GetChildren().GetCount() == 0
646 && m_visitedObjs.find(field.GetObject().GetIndirectReference()) == m_visitedObjs.end())
649 m_visitedObjs.insert(field.GetObject().GetIndirectReference());
653 m_acroFormIterator++;
659 m_visitedObjs.clear();
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:111
PdfPageCollection & GetPages()
Get access to the page tree.
Definition PdfDocument.h:338
const PdfInfo * GetInfo() const
Get access to the internal Info dictionary You can set the author, title etc.
Definition PdfDocument.h:365
const PdfPageCollection & GetPages() const
Get access to the page tree.
Definition PdfDocument.h:343
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:357
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:350
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:326
PdfIndirectObjectList & GetObjects()
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:376
const PdfIndirectObjectList & GetObjects() const
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:383
const PdfCatalog & GetCatalog() const
Get access to the internal Catalog dictionary or root object.
Definition PdfDocument.h:333
A class that is used to encrypt a PDF file and set document permissions on the PDF file.
Definition PdfEncrypt.h:118
PdfExtension is a simple class that describes a vendor-specific extension to the official specificati...
Definition PdfExtension.h:18
This class assists PdfDocument with caching font information.
Definition PdfFontManager.h:54
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition PdfIndirectObjectList.h:31
This class provides access to the documents info dictionary, which provides information about the PDF...
Definition PdfInfo.h:21
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition PdfMemDocument.h:38
Interface to access names trees in the document.
Definition PdfNameTrees.h:22
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
The main PDF outlines dictionary.
Definition PdfOutlines.h:208
Class for managing the tree of Pages in a PDF document Don't use this class directly.
Definition PdfPageCollection.h:24
PdfPage is one page in the pdf document.
Definition PdfPage.h:137
PdfStreamedDocument is the preferred class for creating new PDF documents.
Definition PdfStreamedDocument.h:50
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:20
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
std::shared_ptr< const PdfColorSpaceFilter > PdfColorSpaceFilterPtr
Convenience alias for a constant PdfColorSpaceFilter shared ptr.
Definition PdfColorSpaceFilter.h:85
std::shared_ptr< const PdfShadingDefinition > PdfShadingDefinitionPtr
Convenience alias for a constant PdfShadingDefinition shared ptr.
Definition PdfPatternDefinition.h:167
PdfAcroFormDefaulAppearance
Definition PdfAcroForm.h:17
std::shared_ptr< const PdfShadingPatternDefinition > PdfShadingPatternDefinitionPtr
Convenience alias for a constant PdfShadingPatternDefinition shared ptr.
Definition PdfPatternDefinition.h:414
std::shared_ptr< const PdfExtGStateDefinition > PdfExtGStateDefinitionPtr
Convenience alias for a constant PdfExtGStateDefinition shared ptr.
Definition PdfExtGStateDefinition.h:34
PdfActionType
The type of the action.
Definition PdfAction.h:28
PdfVersion
Enum to identify different versions of the PDF file format.
Definition PdfDeclarations.h:71
std::shared_ptr< const PdfFunctionDefinition > PdfFunctionDefinitionPtr
Convenience alias for a constant PdfFunction shared ptr.
Definition PdfFunctionDefinition.h:58