PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfAcroForm.h
1
7#ifndef PDF_ACRO_FORM_H
8#define PDF_ACRO_FORM_H
9
10#include "PdfField.h"
11
12namespace PoDoFo {
13
14class PdfDocument;
15
17{
18 None = 0,
20};
21
22enum class PdfAcroFormSigFlags
23{
24 None = 0,
25 SignaturesExist = 1,
26 AppendOnly = 2,
27};
28
29class PODOFO_API PdfAcroForm final : public PdfDictionaryElement
30{
31 friend class PdfField;
32 friend class PdfDocument;
33 friend class PdfSigningContext;
34 friend class PdfSignature;
35
36private:
41 PdfAcroForm(PdfDocument & doc,
42 PdfAcroFormDefaulAppearance defaultAppearance = PdfAcroFormDefaulAppearance::ArialBlack);
43
47 PdfAcroForm(PdfObject& obj);
48
49public:
57 void SetNeedAppearances(bool needAppearances);
58
66 bool GetNeedAppearances() const;
67
70 PdfAcroFormSigFlags GetSigFlags() const;
71
72 template <typename TField>
73 TField& CreateField(const std::string_view& name);
74
75 PdfField& CreateField(const std::string_view& name, PdfFieldType fieldType);
76
84 PdfField& GetFieldAt(unsigned index);
85
86 const PdfField& GetFieldAt(unsigned index) const;
87
88 PdfField& GetField(const PdfReference& ref);
89
90 const PdfField& GetField(const PdfReference& ref) const;
91
95 void RemoveFieldAt(unsigned index);
96
100 void RemoveField(const PdfReference& ref);
101
102 unsigned GetFieldCount() const;
103
104public:
105 using FieldList = std::vector<std::shared_ptr<PdfField>>;
106
107 template <typename TObject, typename TListIterator>
108 class Iterator final
109 {
110 friend class PdfAcroForm;
111 public:
112 using difference_type = void;
113 using value_type = TObject*;
114 using pointer = void;
115 using reference = void;
116 using iterator_category = std::forward_iterator_tag;
117 public:
118 Iterator() { }
119 private:
120 Iterator(const TListIterator& iterator) : m_iterator(iterator) { }
121 public:
122 Iterator(const Iterator&) = default;
123 Iterator& operator=(const Iterator&) = default;
124 bool operator==(const Iterator& rhs) const
125 {
126 return m_iterator == rhs.m_iterator;
127 }
128 bool operator!=(const Iterator& rhs) const
129 {
130 return m_iterator != rhs.m_iterator;
131 }
132 Iterator& operator++()
133 {
134 m_iterator++;
135 return *this;
136 }
137 Iterator operator++(int)
138 {
139 auto copy = *this;
140 m_iterator++;
141 return copy;
142 }
143 value_type operator*()
144 {
145 return (*m_iterator).get();
146 }
147 value_type operator->()
148 {
149 return (*m_iterator).get();
150 }
151 private:
152 TListIterator m_iterator;
153 };
154
155 using iterator = Iterator<PdfField, FieldList::iterator>;
156 using const_iterator = Iterator<const PdfField, FieldList::const_iterator>;
157
158public:
159 iterator begin();
160 iterator end();
161 const_iterator begin() const;
162 const_iterator end() const;
163
164private:
165 // To be called by PdfField
166 PdfField& CreateField(PdfObject& obj, PdfFieldType type);
167 PdfField& AddField(std::unique_ptr<PdfField>&& field);
168 std::shared_ptr<PdfField> GetFieldPtr(const PdfReference& ref);
169
170 // To be called by PdfSignature/PdfSigningContext
171 void SetSigFlags(PdfAcroFormSigFlags flags);
172
173private:
178 void init(PdfAcroFormDefaulAppearance defaultAppearance);
179
180 PdfArray* getFieldArray() const;
181
182 void initFields();
183
184 PdfField& getField(unsigned index) const;
185 PdfField& getField(const PdfReference& ref) const;
186
187 void fixIndices(unsigned index);
188
189private:
190 using FieldMap = std::map<PdfReference, unsigned>;
191
192private:
193 FieldList m_Fields;
194 std::unique_ptr<FieldMap> m_fieldMap;
195 PdfArray* m_fieldArray;
196};
197
198template<typename TField>
199TField& PdfAcroForm::CreateField(const std::string_view& name)
200{
201 return static_cast<TField&>(CreateField(name, PdfField::GetFieldType<TField>()));
202}
203
204};
205
206ENABLE_BITMASK_OPERATORS(PoDoFo::PdfAcroFormSigFlags);
207
208#endif // PDF_ACRO_FORM_H
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
PdfAcroFormDefaulAppearance
Definition PdfAcroForm.h:17
@ None
Do not add a default appearrance.
@ ArialBlack
Add a default appearance with Arial embedded and black text if no other DA key is present.