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(
const std::shared_ptr<PdfUncolouredTilingPatternDefinition> &
definition);
167 std::unique_ptr<PdfColouredTilingPattern> CreateTilingPattern(
const 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;
303 virtual const PdfEncrypt* GetEncrypt()
const = 0;
308 bool IsEncrypted()
const;
357 PdfMetadata& GetMetadata() {
return m_Metadata; }
359 const PdfMetadata& GetMetadata()
const {
return m_Metadata; }
375 PdfAcroForm* GetAcroForm() {
return m_AcroForm.get(); }
377 const PdfAcroForm* GetAcroForm()
const {
return m_AcroForm.get(); }
379 PdfNameTrees* GetNames() {
return m_NameTrees.get(); }
381 const PdfNameTrees* GetNames()
const {
return m_NameTrees.get(); }
383 PdfOutlines* GetOutlines();
385 const PdfOutlines* GetOutlines()
const;
387 PdfFontManager& GetFonts() {
return m_FontManager; }
396 void SetTrailer(std::unique_ptr<PdfObject> obj);
402 virtual void reset();
408 virtual void clear();
462 PdfMetadata m_Metadata;
464 std::unique_ptr<PdfObject> m_TrailerObj;
465 std::unique_ptr<PdfTrailer> m_Trailer;
466 std::unique_ptr<PdfCatalog> m_Catalog;
467 std::unique_ptr<PdfInfo> m_Info;
468 std::unique_ptr<PdfPageCollection> m_Pages;
469 std::unique_ptr<PdfAcroForm> m_AcroForm;
471 std::unique_ptr<PdfNameTrees> m_NameTrees;
474template<
typename TAction>
475std::unique_ptr<TAction> PdfDocument::CreateAction()
477 std::unique_ptr<TAction>
ret;
478 createAction(PdfAction::GetActionType<TAction>(),
reinterpret_cast<std::unique_ptr<PdfAction>&
>(
ret));
482template<
typename TField>
483typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::begin()
const
485 if (m_doc ==
nullptr)
488 return Iterator(*m_doc);
491template<
typename TField>
492typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::end()
const
497template<
typename TField>
498PdfDocumentFieldIterableBase<TField>::Iterator::Iterator()
499 : m_doc(nullptr), m_pageIndex(0), m_Field(nullptr)
503template<
typename TField>
504PdfDocumentFieldIterableBase<TField>::Iterator::Iterator(PdfDocument& doc)
505 : m_doc(&doc), m_pageIndex(0), m_Field(nullptr)
507 stepIntoPageOrForm(doc.GetPages());
510template<
typename TField>
511bool PdfDocumentFieldIterableBase<TField>::Iterator::operator==(
const Iterator& rhs)
const
513 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
516 return m_doc == rhs.m_doc && m_pageIndex == rhs.m_pageIndex && m_pageAnnotIterator == rhs.m_pageAnnotIterator && m_acroFormIterator == rhs.m_acroFormIterator;
519template<
typename TField>
520bool PdfDocumentFieldIterableBase<TField>::Iterator::operator!=(
const Iterator& rhs)
const
522 if (m_doc ==
nullptr && rhs.m_doc ==
nullptr)
525 return m_doc != rhs.m_doc || m_pageIndex != rhs.m_pageIndex || m_pageAnnotIterator != rhs.m_pageAnnotIterator || m_acroFormIterator != rhs.m_acroFormIterator;
528template<
typename TField>
529typename PdfDocumentFieldIterableBase<TField>::Iterator& PdfDocumentFieldIterableBase<TField>::Iterator::operator++()
535template<
typename TField>
536typename PdfDocumentFieldIterableBase<TField>::Iterator PdfDocumentFieldIterableBase<TField>::Iterator::operator++(
int)
543template<
typename TField>
544void PdfDocumentFieldIterableBase<TField>::Iterator::increment()
546 if (m_doc ==
nullptr)
549 auto& pages = m_doc->GetPages();
550 if (m_pageIndex < pages.GetCount())
552 m_pageAnnotIterator++;
553 if (stepIntoPageAnnot(pages.GetPageAt(m_pageIndex).GetAnnotations()))
557 stepIntoPageOrForm(pages);
561 m_acroFormIterator++;
562 stepIntoFormField(m_doc->MustGetAcroForm());
567template<
typename TField>
568void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageOrForm(PdfPageCollection& pages)
572 if (m_pageIndex >= pages.GetCount())
575 auto& annots = pages.GetPageAt(m_pageIndex).GetAnnotations();
576 m_pageAnnotIterator = annots.begin();
577 if (stepIntoPageAnnot(annots))
583 auto form = m_doc->GetAcroForm();
586 m_acroFormIterator = form->begin();
587 stepIntoFormField(*form);
594 m_visitedObjs.clear();
599template<
typename TField>
600bool PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoPageAnnot(PdfAnnotationCollection& annots)
604 if (m_pageAnnotIterator == annots.end())
607 auto& annot = **m_pageAnnotIterator;
608 PdfField* field =
nullptr;
609 if (annot.GetType() == PdfAnnotationType::Widget &&
610 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
611 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
614 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
618 m_pageAnnotIterator++;
626template<
typename TField>
627void PdfDocumentFieldIterableBase<TField>::Iterator::stepIntoFormField(PdfAcroForm& form)
631 if (m_acroFormIterator == form.end())
634 auto& field = **m_acroFormIterator;
635 if (field.GetChildren().GetCount() == 0
636 && m_visitedObjs.find(field.GetObject().GetIndirectReference()) == m_visitedObjs.end())
639 m_visitedObjs.insert(field.GetObject().GetIndirectReference());
643 m_acroFormIterator++;
649 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:328
const PdfInfo * GetInfo() const
Get access to the internal Info dictionary You can set the author, title etc.
Definition PdfDocument.h:355
const PdfPageCollection & GetPages() const
Get access to the page tree.
Definition PdfDocument.h:333
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:347
PdfTrailer & GetTrailer()
Get access to the internal trailer dictionary or root object.
Definition PdfDocument.h:340
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:316
PdfIndirectObjectList & GetObjects()
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:366
const PdfIndirectObjectList & GetObjects() const
Get access to the internal vector of objects or root object.
Definition PdfDocument.h:373
const PdfCatalog & GetCatalog() const
Get access to the internal Catalog dictionary or root object.
Definition PdfDocument.h:323
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:30
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:129
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