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
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>;
159 const PdfTextExtractParams&
params)
const;
166 const std::string_view&
pattern = { },
167 const PdfTextExtractParams&
params = { })
const;
177 Corners GetRectRaw()
const override;
181 bool TryGetRotationRadians(
double&
teta)
const override;
185 double GetRotationRadians()
const;
211 unsigned GetPageNumber()
const;
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;
262 bool MoveTo(
unsigned index);
264 template <
typename TField>
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; }
291 void CopyContentsTo(OutputStream& stream)
const override;
293 PdfObjectStream& GetOrCreateContentsStream(PdfStreamAppendFlags flags)
override;
295 PdfObjectStream& ResetContentsStream()
override;
297 PdfResources& GetOrCreateResources()
override;
299 PdfResources* getResources()
override;
301 PdfObject* getContentsObject()
override;
303 PdfDictionaryElement& getElement()
override;
305 PdfObject* findInheritableAttribute(
const std::string_view& name)
const;
307 PdfObject* findInheritableAttribute(
const std::string_view& name,
bool& isShallow)
const;
309 void ensureContentsCreated();
316 Rect getPageBox(
const std::string_view& inBox,
bool isInheritable)
const;
323 Corners getPageBoxRaw(
const std::string_view& inBox,
bool isInheritable)
const;
328 void setPageBox(
const PdfName& inBox,
const Rect& rect);
330 void adjustRectToCurrentRotation(Rect& rect)
const;
334 PdfElement& GetElement() =
delete;
335 const PdfElement& GetElement()
const =
delete;
336 PdfObject* GetContentsObject() =
delete;
337 const PdfObject* GetContentsObject()
const =
delete;
343 std::vector<PdfObject*> m_parents;
344 std::unique_ptr<PdfContents> m_Contents;
345 std::unique_ptr<PdfResources> m_Resources;
346 PdfAnnotationCollection m_Annotations;
349template<
typename TField>
350TField& PdfPage::CreateField(
const std::string_view& name,
const Rect & rect)
352 return static_cast<TField&
>(CreateField(name, PdfField::GetFieldType<TField>(), rect));
355template<
typename TField>
356typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::begin()
const
358 if (m_page ==
nullptr)
361 return Iterator(m_page->GetAnnotations().begin(), m_page->GetAnnotations().end());
364template<
typename TField>
365typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::end()
const
367 if (m_page ==
nullptr)
370 return Iterator(m_page->GetAnnotations().end(), m_page->GetAnnotations().end());
373template<
typename TField>
374void PdfPageFieldIterableBase<TField>::Iterator::stepIntoPageAnnot()
378 if (m_annotsIterator == m_annotsEnd)
381 auto& annot = **m_annotsIterator;
382 PdfField* field =
nullptr;
383 if (annot.GetType() == PdfAnnotationType::Widget &&
384 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
385 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
388 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
396 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
Class for managing the tree of Pages in a PDF document Don't use this class directly.
Definition PdfPageCollection.h:37
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
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
PdfFieldType
The type of PDF field.
Definition PdfDeclarations.h:610
PdfTextExtractFlags
Definition PdfDeclarations.h:184
A structure with status progress attributes of certain operations.
Definition PdfPage.h:36