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;
38 unsigned ReadCount = 0;
41struct PODOFO_API PdfTextExtractParams
final
50template <
typename TField>
51class PdfPageFieldIterableBase final
56 PdfPageFieldIterableBase()
60 PdfPageFieldIterableBase(PdfPage& page)
66 friend class PdfPageFieldIterableBase;
68 using difference_type = void;
69 using value_type = TField*;
71 using reference = void;
72 using iterator_category = std::forward_iterator_tag;
75 : m_Field(nullptr) { }
77 void stepIntoPageAnnot();
79 Iterator(PdfAnnotationCollection::iterator begin,
80 PdfAnnotationCollection::iterator end)
81 : m_annotsIterator(std::move(begin)), m_annotsEnd(std::move(end)), m_Field(nullptr)
87 Iterator(
const Iterator&) =
default;
88 Iterator& operator=(
const Iterator&) =
default;
89 bool operator==(
const Iterator& rhs)
const
91 return m_annotsIterator == rhs.m_annotsIterator;
93 bool operator!=(
const Iterator& rhs)
const
95 return m_annotsIterator != rhs.m_annotsIterator;
97 Iterator& operator++()
103 Iterator operator++(
int)
110 value_type operator*() {
return m_Field; }
111 value_type operator->() {
return m_Field; }
113 PdfAnnotationCollection::iterator m_annotsIterator;
114 PdfAnnotationCollection::iterator m_annotsEnd;
116 std::unordered_set<PdfReference> m_visitedObjs;
120 Iterator begin()
const;
121 Iterator end()
const;
127using PdfPageFieldIterable = PdfPageFieldIterableBase<PdfField>;
128using PdfPageConstFieldIterable = PdfPageFieldIterableBase<const PdfField>;
159 void ExtractTextTo(std::vector<PdfTextEntry>&
entries,
160 const PdfTextExtractParams&
params)
const;
162 void ExtractTextTo(std::vector<PdfTextEntry>&
entries,
163 const std::string_view&
pattern = { },
164 const PdfTextExtractParams&
params = { })
const;
176 Corners GetRectRaw()
const override;
180 bool TryGetRotationRadians(
double&
teta)
const override;
185 double GetRotationRadians()
const;
217 unsigned GetPageNumber()
const;
231 Rect GetMediaBox()
const;
232 Corners GetMediaBoxRaw()
const;
237 Rect GetCropBox()
const;
243 Rect GetTrimBox()
const;
249 Rect GetBleedBox()
const;
250 Corners GetBleedBoxRaw()
const;
255 Rect GetArtBox()
const;
267 bool TryGetRotationRaw(
double&
rotation)
const;
277 bool MoveTo(
unsigned index);
279 template <
typename TField>
292 unsigned GetIndex()
const {
return m_Index; }
293 PdfContents& GetOrCreateContents();
294 inline const PdfContents* GetContents()
const {
return m_Contents.get(); }
295 inline PdfContents* GetContents() {
return m_Contents.get(); }
296 const PdfContents& MustGetContents()
const;
297 PdfContents& MustGetContents();
298 const PdfResources& GetResources()
const;
299 PdfResources& GetResources();
300 inline PdfAnnotationCollection& GetAnnotations() {
return m_Annotations; }
301 inline const PdfAnnotationCollection& GetAnnotations()
const {
return m_Annotations; }
305 void FlattenStructure();
306 void SetIndex(
unsigned index) { m_Index = index; }
308 void CopyContentsTo(OutputStream& stream)
const override;
310 PdfObjectStream& GetOrCreateContentsStream(PdfStreamAppendFlags flags)
override;
312 PdfObjectStream& ResetContentsStream()
override;
314 PdfResources& GetOrCreateResources()
override;
316 PdfResources* getResources()
override;
318 PdfObject* getContentsObject()
override;
320 PdfDictionaryElement& getElement()
override;
322 PdfObject* findInheritableAttribute(
const std::string_view& name)
const;
324 PdfObject* findInheritableAttribute(
const std::string_view& name,
bool& isShallow)
const;
326 void ensureContentsCreated();
332 Rect getPageBox(
const std::string_view& inBox,
bool isInheritable)
const;
334 Corners getPageBoxRaw(
const std::string_view& inBox,
bool isInheritable)
const;
336 void setPageBox(
const PdfName& inBox,
const Rect& rect);
338 void adjustRectToCurrentRotation(Rect& rect)
const;
342 PdfElement& GetElement() =
delete;
343 const PdfElement& GetElement()
const =
delete;
344 PdfObject* GetContentsObject() =
delete;
345 const PdfObject* GetContentsObject()
const =
delete;
351 std::vector<PdfObject*> m_parents;
352 std::unique_ptr<PdfContents> m_Contents;
353 std::unique_ptr<PdfResources> m_Resources;
354 PdfAnnotationCollection m_Annotations;
357template<
typename TField>
358TField& PdfPage::CreateField(
const std::string_view& name,
const Rect & rect)
360 return static_cast<TField&
>(CreateField(name, PdfField::GetFieldType<TField>(), rect));
363template<
typename TField>
364typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::begin()
const
366 if (m_page ==
nullptr)
369 return Iterator(m_page->GetAnnotations().begin(), m_page->GetAnnotations().end());
372template<
typename TField>
373typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::end()
const
375 if (m_page ==
nullptr)
378 return Iterator(m_page->GetAnnotations().end(), m_page->GetAnnotations().end());
381template<
typename TField>
382void PdfPageFieldIterableBase<TField>::Iterator::stepIntoPageAnnot()
386 if (m_annotsIterator == m_annotsEnd)
389 auto& annot = **m_annotsIterator;
390 PdfField* field =
nullptr;
391 if (annot.GetType() == PdfAnnotationType::Widget &&
392 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
393 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
396 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
404 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:17
An interface that provides the necessary features for a painter to draw onto a PdfObject.
Definition PdfCanvas.h:26
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:109
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:33
Class for managing the tree of Pages in a PDF document Don't use this class directly.
Definition PdfPageCollection.h:22
PdfPage is one page in the pdf document.
Definition PdfPage.h:135
Rect GetRect() const
Get the rectangle of this page.
Definition PdfPage.h:169
unsigned GetRotation() const
Get the normalized page rotation (0, 90, 180 or 270)
Definition PdfPage.h:261
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:18
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:35
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:533
PdfFieldType
The type of PDF field.
Definition PdfDeclarations.h:665
PdfTextExtractFlags
Definition PdfDeclarations.h:197
A structure with status progress attributes of certain operations.
Definition PdfPage.h:37