12#include <podofo/auxiliary/Rect.h>
14#include "PdfAnnotationCollection.h"
16#include "PdfContents.h"
18#include "PdfResources.h"
26struct PODOFO_API PdfTextEntry final
33 nullable<Rect> BoundingBox;
36struct PODOFO_API PdfTextExtractParams final
38 nullable<Rect> ClipRect;
41 std::function<bool(
int read_cnt)> AbortCheck =
nullptr;
44template <
typename TField>
45class PdfPageFieldIterableBase final
50 PdfPageFieldIterableBase()
54 PdfPageFieldIterableBase(PdfPage& page)
60 friend class PdfPageFieldIterableBase;
62 using difference_type = void;
63 using value_type = TField*;
65 using reference = void;
66 using iterator_category = std::forward_iterator_tag;
69 : m_Field(nullptr) { }
71 void stepIntoPageAnnot();
73 Iterator(PdfAnnotationCollection::iterator begin,
74 PdfAnnotationCollection::iterator end)
75 : m_annotsIterator(std::move(begin)), m_annotsEnd(std::move(end)), m_Field(nullptr)
81 Iterator(
const Iterator&) =
default;
82 Iterator& operator=(
const Iterator&) =
default;
83 bool operator==(
const Iterator& rhs)
const
85 return m_annotsIterator == rhs.m_annotsIterator;
87 bool operator!=(
const Iterator& rhs)
const
89 return m_annotsIterator != rhs.m_annotsIterator;
91 Iterator& operator++()
97 Iterator operator++(
int)
104 value_type operator*() {
return m_Field; }
105 value_type operator->() {
return m_Field; }
107 PdfAnnotationCollection::iterator m_annotsIterator;
108 PdfAnnotationCollection::iterator m_annotsEnd;
110 std::unordered_set<PdfReference> m_visitedObjs;
114 Iterator begin()
const;
115 Iterator end()
const;
121using PdfPageFieldIterable = PdfPageFieldIterableBase<PdfField>;
122using PdfPageConstFieldIterable = PdfPageFieldIterableBase<const PdfField>;
153 void ExtractTextTo(std::vector<PdfTextEntry>&
entries,
154 const PdfTextExtractParams&
params)
const;
156 void ExtractTextTo(std::vector<PdfTextEntry>&
entries,
157 const std::string_view&
pattern = { },
158 const PdfTextExtractParams&
params = { })
const;
170 Corners GetRectRaw()
const override;
174 bool TryGetRotationRadians(
double&
teta)
const override;
179 double GetRotationRadians()
const;
211 unsigned GetPageNumber()
const;
225 Rect GetMediaBox()
const;
226 Corners GetMediaBoxRaw()
const;
231 Rect GetCropBox()
const;
237 Rect GetTrimBox()
const;
243 Rect GetBleedBox()
const;
244 Corners GetBleedBoxRaw()
const;
249 Rect GetArtBox()
const;
261 bool TryGetRotationRaw(
double&
rotation)
const;
271 bool MoveTo(
unsigned index);
273 template <
typename TField>
274 TField& CreateField(
const std::string_view& name,
const Rect&
rect);
286 unsigned GetIndex()
const {
return m_Index; }
287 PdfContents& GetOrCreateContents();
288 inline const PdfContents* GetContents()
const {
return m_Contents.get(); }
289 inline PdfContents* GetContents() {
return m_Contents.get(); }
290 const PdfContents& MustGetContents()
const;
291 PdfContents& MustGetContents();
292 const PdfResources& GetResources()
const;
293 PdfResources& GetResources();
294 inline PdfAnnotationCollection& GetAnnotations() {
return m_Annotations; }
295 inline const PdfAnnotationCollection& GetAnnotations()
const {
return m_Annotations; }
299 void FlattenStructure();
300 void SetIndex(
unsigned index) { m_Index = index; }
302 void CopyContentsTo(OutputStream& stream)
const override;
304 PdfObjectStream& GetOrCreateContentsStream(PdfStreamAppendFlags flags)
override;
306 PdfObjectStream& ResetContentsStream()
override;
308 PdfResources& GetOrCreateResources()
override;
310 PdfResources* getResources()
override;
312 PdfObject* getContentsObject()
override;
314 PdfDictionaryElement& getElement()
override;
316 PdfObject* findInheritableAttribute(
const std::string_view& name)
const;
318 PdfObject* findInheritableAttribute(
const std::string_view& name,
bool& isShallow)
const;
320 void ensureContentsCreated();
326 Rect getPageBox(
const std::string_view& inBox,
bool isInheritable)
const;
328 Corners getPageBoxRaw(
const std::string_view& inBox,
bool isInheritable)
const;
330 void setPageBox(
const PdfName& inBox,
const Rect& rect);
332 void adjustRectToCurrentRotation(Rect& rect)
const;
336 PdfElement& GetElement() =
delete;
337 const PdfElement& GetElement()
const =
delete;
338 PdfObject* GetContentsObject() =
delete;
339 const PdfObject* GetContentsObject()
const =
delete;
345 std::vector<PdfObject*> m_parents;
346 std::unique_ptr<PdfContents> m_Contents;
347 std::unique_ptr<PdfResources> m_Resources;
348 PdfAnnotationCollection m_Annotations;
351template<
typename TField>
352TField& PdfPage::CreateField(
const std::string_view& name,
const Rect & rect)
354 return static_cast<TField&
>(CreateField(name, PdfField::GetFieldType<TField>(), rect));
357template<
typename TField>
358typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::begin()
const
360 if (m_page ==
nullptr)
363 return Iterator(m_page->GetAnnotations().begin(), m_page->GetAnnotations().end());
366template<
typename TField>
367typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::end()
const
369 if (m_page ==
nullptr)
372 return Iterator(m_page->GetAnnotations().end(), m_page->GetAnnotations().end());
375template<
typename TField>
376void PdfPageFieldIterableBase<TField>::Iterator::stepIntoPageAnnot()
380 if (m_annotsIterator == m_annotsEnd)
383 auto& annot = **m_annotsIterator;
384 PdfField* field =
nullptr;
385 if (annot.GetType() == PdfAnnotationType::Widget &&
386 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
387 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
390 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
398 m_visitedObjs.clear();
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
An unoriented rectangle defined by 2 points.
Definition Corners.h:20
A interface that provides the necessary features for a painter to draw onto a PdfObject.
Definition PdfCanvas.h:28
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
Rect GetRect() const
Get the rectangle of this page.
Definition PdfPage.h:163
unsigned GetRotation() const
Get the normalized page rotation (0, 90, 180 or 270)
Definition PdfPage.h:255
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
PdfFieldType
The type of PDF field.
Definition PdfDeclarations.h:650
PdfTextExtractFlags
Definition PdfDeclarations.h:199