PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfPageCollection.h
1
7#ifndef PDF_PAGES_TREE_H
8#define PDF_PAGES_TREE_H
9
10#include "PdfDeclarations.h"
11
12#include "PdfElement.h"
13#include "PdfArray.h"
14#include "PdfPage.h"
15
16namespace PoDoFo {
17
23class PODOFO_API PdfPageCollection final : public PdfDictionaryElement
24{
25 friend class PdfDocument;
26 friend class PdfPage;
27
28public:
32
37
40 virtual ~PdfPageCollection();
41
45 unsigned GetCount() const;
46
54 PdfPage& GetPageAt(unsigned index);
55 const PdfPage& GetPageAt(unsigned index) const;
56
64 PdfPage& GetPage(const PdfReference& ref);
65 const PdfPage& GetPage(const PdfReference& ref) const;
66
75 PdfPage& CreatePage(const nullable<Rect>& size = nullptr);
76 PdfPage& CreatePage(PdfPageSize pageSize);
77
86 PdfPage& CreatePageAt(unsigned atIndex, const nullable<Rect>& size = nullptr);
87 PdfPage& CreatePageAt(unsigned atIndex, PdfPageSize pageSize);
88
96 void CreatePagesAt(unsigned atIndex, unsigned count, const nullable<Rect>& size = nullptr);
97 void CreatePagesAt(unsigned atIndex, unsigned count, PdfPageSize pageSize);
98
102 void AppendDocumentPages(const PdfDocument& doc);
103
109 void AppendDocumentPages(const PdfDocument& doc, unsigned pageIndex, unsigned pageCount);
110
116 void InsertDocumentPageAt(unsigned atIndex, const PdfDocument& doc, unsigned pageIndex);
117
128 void RemovePageAt(unsigned atIndex);
129
135 void FlattenStructure();
136
137public:
138 template <typename TObject, typename TListIterator>
139 class Iterator final
140 {
141 friend class PdfPageCollection;
142 public:
143 using difference_type = void;
144 using value_type = TObject*;
145 using pointer = void;
146 using reference = void;
147 using iterator_category = std::forward_iterator_tag;
148 public:
149 Iterator() { }
150 private:
151 Iterator(const TListIterator& iterator) : m_iterator(iterator) { }
152 public:
153 Iterator(const Iterator&) = default;
154 Iterator& operator=(const Iterator&) = default;
155 bool operator==(const Iterator& rhs) const
156 {
157 return m_iterator == rhs.m_iterator;
158 }
159 bool operator!=(const Iterator& rhs) const
160 {
161 return m_iterator != rhs.m_iterator;
162 }
163 Iterator& operator++()
164 {
165 m_iterator++;
166 return *this;
167 }
168 Iterator operator++(int)
169 {
170 auto copy = *this;
171 m_iterator++;
172 return copy;
173 }
174 value_type operator*()
175 {
176 return *m_iterator;
177 }
178 value_type operator->()
179 {
180 return *m_iterator;
181 }
182 private:
183 TListIterator m_iterator;
184 };
185
186 using PageList = std::vector<PdfPage*>;
187
190
191 public:
192 iterator begin();
193 iterator end();
194 const_iterator begin() const;
195 const_iterator end() const;
196
197private:
202 void InsertPageAt(unsigned atIndex, PdfPage& page);
203
208 void InsertPagesAt(unsigned atIndex, cspan<PdfPage*> pages);
209
210 bool TryMovePageTo(unsigned atIndex, unsigned toIndex);
211
212private:
213 void insertPageAt(unsigned atIndex, PdfPage& page);
214 void insertPagesAt(unsigned atIndex, cspan<PdfPage*> pages);
215 Rect getActualRect(const nullable<Rect>& size);
216
217 PdfPage& getPage(const PdfReference& ref) const;
218
219 void initPages();
220
221 unsigned traversePageTreeNode(PdfObject& obj, unsigned count,
222 std::vector<PdfObject*>& parents, std::unordered_set<PdfObject*>& visitedNodes);
223
225 PdfPageCollection& operator=(PdfPageCollection&) = delete;
226
227private:
228 bool m_initialized;
229 PageList m_Pages;
230 PdfArray* m_kidsArray;
231};
232
233};
234
235#endif // PDF_PAGES_TREE_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:81
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:111
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
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
A reference is a pointer to a object in the PDF file of the form "4 0 R", where 4 is the object numbe...
Definition PdfReference.h:24
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
PdfPageSize
Enum holding the supported page sizes by PoDoFo.
Definition PdfDeclarations.h:518