PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfPageCollection.h
1// SPDX-FileCopyrightText: 2006 Dominik Seichter <domseichter@web.de>
2// SPDX-FileCopyrightText: 2021 Francesco Pretto <ceztko@gmail.com>
3// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
4
5#ifndef PDF_PAGES_COLLECTION_H
6#define PDF_PAGES_COLLECTION_H
7
8#include "PdfDeclarations.h"
9
10#include "PdfElement.h"
11#include "PdfArray.h"
12#include "PdfPage.h"
13
14namespace PoDoFo {
15
20 class PODOFO_API PdfPageCollection final : public PdfDictionaryElement
21 {
22 friend class PdfDocument;
23 friend class PdfPage;
24
25 public:
28
32
34 virtual ~PdfPageCollection();
35
38 unsigned GetCount() const;
39
46 PdfPage& GetPageAt(unsigned index);
47 const PdfPage& GetPageAt(unsigned index) const;
48
55 PdfPage& GetPage(const PdfReference& ref);
56 const PdfPage& GetPage(const PdfReference& ref) const;
57
65 PdfPage& CreatePage(const nullable<Rect>& size = nullptr);
66 PdfPage& CreatePage(PdfPageSize pageSize);
67
75 PdfPage& CreatePageAt(unsigned atIndex, const nullable<Rect>& size = nullptr);
76 PdfPage& CreatePageAt(unsigned atIndex, PdfPageSize pageSize);
77
84 void CreatePagesAt(unsigned atIndex, unsigned count, const nullable<Rect>& size = nullptr);
85 void CreatePagesAt(unsigned atIndex, unsigned count, PdfPageSize pageSize);
86
89 void AppendDocumentPages(const PdfDocument& doc);
90
95 void AppendDocumentPages(const PdfDocument& doc, unsigned pageIndex, unsigned pageCount);
96
101 void InsertDocumentPageAt(unsigned atIndex, const PdfDocument& doc, unsigned pageIndex);
102
112 void RemovePageAt(unsigned atIndex);
113
118 void FlattenStructure();
119
120 public:
121 template <typename TObject, typename TListIterator>
122 class Iterator final
123 {
124 friend class PdfPageCollection;
125 public:
126 using difference_type = void;
127 using value_type = TObject*;
128 using pointer = void;
129 using reference = void;
130 using iterator_category = std::forward_iterator_tag;
131 public:
132 Iterator() {}
133 private:
134 Iterator(const TListIterator& iterator) : m_iterator(iterator) {}
135 public:
136 Iterator(const Iterator&) = default;
137 Iterator& operator=(const Iterator&) = default;
138 bool operator==(const Iterator& rhs) const
139 {
140 return m_iterator == rhs.m_iterator;
141 }
142 bool operator!=(const Iterator& rhs) const
143 {
144 return m_iterator != rhs.m_iterator;
145 }
146 Iterator& operator++()
147 {
148 m_iterator++;
149 return *this;
150 }
151 Iterator operator++(int)
152 {
153 auto copy = *this;
154 m_iterator++;
155 return copy;
156 }
157 value_type operator*()
158 {
159 return *m_iterator;
160 }
161 value_type operator->()
162 {
163 return *m_iterator;
164 }
165 private:
166 TListIterator m_iterator;
167 };
168
169 using PageList = std::vector<PdfPage*>;
170
173
174 public:
175 iterator begin();
176 iterator end();
177 const_iterator begin() const;
178 const_iterator end() const;
179
180 private:
183 void InsertPageAt(unsigned atIndex, std::unique_ptr<PdfPage> page);
184
187 void InsertPagesAt(unsigned atIndex, mspan<std::unique_ptr<PdfPage>> pages);
188
189 bool TryMovePageTo(unsigned atIndex, unsigned toIndex);
190
191 private:
192 void insertPageAt(unsigned atIndex, std::unique_ptr<PdfPage> page);
193 void insertPagesAt(unsigned atIndex, mspan<std::unique_ptr<PdfPage>> pages);
194 Rect getActualRect(const nullable<Rect>& size);
195
196 PdfPage& getPage(const PdfReference& ref) const;
197
198 void initPages();
199
200 unsigned traversePageTreeNode(PdfObject& obj, unsigned count,
201 std::vector<PdfObject*>& parents, std::unordered_set<PdfObject*>& visitedNodes);
202
204 PdfPageCollection& operator=(PdfPageCollection&) = delete;
205
206 private:
207 bool m_initialized;
208 PageList m_Pages;
209 PdfArray* m_kidsArray;
210 };
211
212};
213
214#endif // PDF_PAGES_COLLECTION_H
This file should be included as the FIRST file in every header of PoDoFo lib.
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:76
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:108
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
Class for managing the tree of Pages in a PDF document Don't use this class directly.
Definition PdfPageCollection.h:21
PdfPage is one page in the pdf document.
Definition PdfPage.h:133
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:20
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
PdfPageSize
Enum holding the supported page sizes by PoDoFo.
Definition PdfDeclarations.h:485
tcb::span< T, Extent > mspan
Mutable span.
Definition span.h:22