10#include <podofo/auxiliary/Rect.h>
12#include "PdfAnnotationCollection.h"
14#include "PdfContents.h"
16#include "PdfResources.h"
24struct PODOFO_API PdfTextEntry final
31 nullable<Rect> BoundingBox;
37 unsigned ReadCount = 0;
40struct PODOFO_API PdfTextExtractParams final
46 std::function<bool(
const AbortCheckInfo& info)> AbortCheck =
nullptr;
49template <
typename TField>
50class PdfPageFieldIterableBase final
55 PdfPageFieldIterableBase()
59 PdfPageFieldIterableBase(PdfPage& page)
65 friend class PdfPageFieldIterableBase;
67 using difference_type = void;
68 using value_type = TField*;
70 using reference = void;
71 using iterator_category = std::forward_iterator_tag;
74 : m_Field(nullptr) { }
76 void stepIntoPageAnnot();
78 Iterator(PdfAnnotationCollection::iterator begin,
79 PdfAnnotationCollection::iterator end)
80 : m_annotsIterator(std::move(begin)), m_annotsEnd(std::move(end)), m_Field(nullptr)
86 Iterator(
const Iterator&) =
default;
87 Iterator& operator=(
const Iterator&) =
default;
88 bool operator==(
const Iterator& rhs)
const
90 return m_annotsIterator == rhs.m_annotsIterator;
92 bool operator!=(
const Iterator& rhs)
const
94 return m_annotsIterator != rhs.m_annotsIterator;
96 Iterator& operator++()
102 Iterator operator++(
int)
109 value_type operator*() {
return m_Field; }
110 value_type operator->() {
return m_Field; }
112 PdfAnnotationCollection::iterator m_annotsIterator;
113 PdfAnnotationCollection::iterator m_annotsEnd;
115 std::unordered_set<PdfReference> m_visitedObjs;
119 Iterator begin()
const;
120 Iterator end()
const;
126using PdfPageFieldIterable = PdfPageFieldIterableBase<PdfField>;
127using PdfPageConstFieldIterable = PdfPageFieldIterableBase<const PdfField>;
132class PODOFO_API PdfPage final :
public PdfDictionaryElement,
public PdfCanvas
134 PODOFO_PRIVATE_FRIEND(
class PdfPageTest);
135 friend class PdfPageCollection;
136 friend class PdfDocument;
142 PdfPage(PdfDocument& parent,
const Rect& size);
152 PdfPage(
PdfObject& obj, std::vector<PdfObject*>&& parents);
159 const PdfTextExtractParams& params)
const;
166 const std::string_view& pattern = { },
167 const PdfTextExtractParams& params = { })
const;
175 void SetRect(
const Rect& rect);
177 Corners GetRectRaw()
const override;
179 void SetRectRaw(
const Corners& rect);
181 bool TryGetRotationRadians(
double& teta)
const override;
185 double GetRotationRadians()
const;
189 void SetMediaBox(
const Rect& rect);
193 void SetCropBox(
const Rect& rect);
197 void SetTrimBox(
const Rect& rect);
201 void SetBleedBox(
const Rect& rect);
205 void SetArtBox(
const Rect& rect);
211 unsigned GetPageNumber()
const;
219 static Rect CreateStandardPageSize(
const PdfPageSize pageSize,
bool landscape =
false);
223 Rect GetMediaBox()
const;
224 Corners GetMediaBoxRaw()
const;
228 Rect GetCropBox()
const;
233 Rect GetTrimBox()
const;
238 Rect GetBleedBox()
const;
239 Corners GetBleedBoxRaw()
const;
243 Rect GetArtBox()
const;
253 bool TryGetRotationRaw(
double& rotation)
const;
258 void SetRotation(
int rotation);
262 bool MoveTo(
unsigned index);
264 template <
typename TField>
265 TField& CreateField(
const std::string_view& name,
const Rect& rect);
267 PdfField& CreateField(
const std::string_view& name,
PdfFieldType fieldType,
const Rect& rect);
271 PdfPageFieldIterable GetFieldsIterator();
272 PdfPageConstFieldIterable GetFieldsIterator()
const;
275 unsigned GetIndex()
const {
return m_Index; }
276 PdfContents& GetOrCreateContents();
277 inline const PdfContents* GetContents()
const {
return m_Contents.get(); }
278 inline PdfContents* GetContents() {
return m_Contents.get(); }
279 const PdfContents& MustGetContents()
const;
280 PdfContents& MustGetContents();
281 const PdfResources& GetResources()
const;
282 PdfResources& GetResources();
283 inline PdfAnnotationCollection& GetAnnotations() {
return m_Annotations; }
284 inline const PdfAnnotationCollection& GetAnnotations()
const {
return m_Annotations; }
288 void FlattenStructure();
289 void SetIndex(
unsigned index) { m_Index = index; }
290 static cspan<PdfName> GetInheritableAttributes();
292 void CopyContentsTo(OutputStream& stream)
const override;
294 PdfObjectStream& GetOrCreateContentsStream(PdfStreamAppendFlags flags)
override;
296 PdfObjectStream& ResetContentsStream()
override;
298 PdfResources& GetOrCreateResources()
override;
300 PdfResources* getResources()
override;
302 PdfObject* getContentsObject()
override;
304 PdfDictionaryElement& getElement()
override;
306 PdfObject* findInheritableAttribute(
const std::string_view& name)
const;
308 void ensureContentsCreated();
315 Rect getPageBox(
const std::string_view& inBox,
bool isInheritable)
const;
322 Corners getPageBoxRaw(
const std::string_view& inBox,
bool isInheritable)
const;
327 void setPageBox(
const PdfName& inBox,
const Rect& rect);
329 void adjustRectToCurrentRotation(Rect& rect)
const;
333 PdfElement& GetElement() =
delete;
334 const PdfElement& GetElement()
const =
delete;
335 PdfObject* GetContentsObject() =
delete;
336 const PdfObject* GetContentsObject()
const =
delete;
342 std::vector<PdfObject*> m_parents;
343 std::unique_ptr<PdfContents> m_Contents;
344 std::unique_ptr<PdfResources> m_Resources;
345 PdfAnnotationCollection m_Annotations;
348template<
typename TField>
349TField& PdfPage::CreateField(
const std::string_view& name,
const Rect & rect)
351 return static_cast<TField&
>(CreateField(name, PdfField::GetFieldType<TField>(), rect));
354template<
typename TField>
355typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::begin()
const
357 if (m_page ==
nullptr)
360 return Iterator(m_page->GetAnnotations().begin(), m_page->GetAnnotations().end());
363template<
typename TField>
364typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::end()
const
366 if (m_page ==
nullptr)
369 return Iterator(m_page->GetAnnotations().end(), m_page->GetAnnotations().end());
372template<
typename TField>
373void PdfPageFieldIterableBase<TField>::Iterator::stepIntoPageAnnot()
377 if (m_annotsIterator == m_annotsEnd)
380 auto& annot = **m_annotsIterator;
381 PdfField* field =
nullptr;
382 if (annot.GetType() == PdfAnnotationType::Widget &&
383 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
384 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
387 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
395 m_visitedObjs.clear();
This file should be included as the FIRST file in every header of PoDoFo lib.
An unoriented rectangle defined by 2 points.
Definition Corners.h:16
An interface that provides the necessary features for a painter to draw onto a PdfObject.
Definition PdfCanvas.h:25
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
PdfPage is one page in the pdf document.
Definition PdfPage.h:133
Rect GetRect() const
Get the rectangle of this page.
Definition PdfPage.h:171
void ExtractTextTo(std::vector< PdfTextEntry > &entries, const PdfTextExtractParams ¶ms) const
Extract text from the page.
void ExtractTextTo(std::vector< PdfTextEntry > &entries, const std::string_view &pattern={ }, const PdfTextExtractParams ¶ms={ }) const
Extract text from the page.
unsigned GetRotation() const
Get the normalized page rotation (0, 90, 180 or 270).
Definition PdfPage.h:248
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:17
Alternative to std::optional that supports reference (but not pointer) types.
Definition nullable.h:24
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:494
PdfFieldType
The type of PDF field.
Definition PdfDeclarations.h:619
PdfTextExtractFlags
Definition PdfDeclarations.h:184
A structure with status progress attributes of certain operations.
Definition PdfPage.h:36