12 #include <podofo/auxiliary/Rect.h>
14 #include "PdfAnnotationCollection.h"
15 #include "PdfCanvas.h"
16 #include "PdfContents.h"
18 #include "PdfResources.h"
26 struct PODOFO_API PdfTextEntry final
33 nullable<Rect> BoundingBox;
36 struct PODOFO_API PdfTextExtractParams final
38 nullable<Rect> ClipRect;
42 template <
typename TField>
43 class PdfPageFieldIterableBase final
48 PdfPageFieldIterableBase()
52 PdfPageFieldIterableBase(PdfPage& page)
58 friend class PdfPageFieldIterableBase;
60 using difference_type = void;
61 using value_type = TField*;
63 using reference = void;
64 using iterator_category = std::forward_iterator_tag;
67 : m_Field(nullptr) { }
69 void stepIntoPageAnnot();
71 Iterator(PdfAnnotationCollection::iterator begin,
72 PdfAnnotationCollection::iterator end)
73 : m_annotsIterator(std::move(begin)), m_annotsEnd(std::move(end)), m_Field(nullptr)
79 Iterator(
const Iterator&) =
default;
80 Iterator& operator=(
const Iterator&) =
default;
81 bool operator==(
const Iterator& rhs)
const
83 return m_annotsIterator == rhs.m_annotsIterator;
85 bool operator!=(
const Iterator& rhs)
const
87 return m_annotsIterator != rhs.m_annotsIterator;
89 Iterator& operator++()
95 Iterator operator++(
int)
102 value_type operator*() {
return m_Field; }
103 value_type operator->() {
return m_Field; }
105 PdfAnnotationCollection::iterator m_annotsIterator;
106 PdfAnnotationCollection::iterator m_annotsEnd;
108 std::unordered_set<PdfReference> m_visitedObjs;
112 Iterator begin()
const;
113 Iterator end()
const;
119 using PdfPageFieldIterable = PdfPageFieldIterableBase<PdfField>;
120 using PdfPageConstFieldIterable = PdfPageFieldIterableBase<const PdfField>;
128 PODOFO_PRIVATE_FRIEND(
class PdfPageTest);
151 void ExtractTextTo(std::vector<PdfTextEntry>& entries,
152 const PdfTextExtractParams& params)
const;
154 void ExtractTextTo(std::vector<PdfTextEntry>& entries,
155 const std::string_view& pattern = { },
156 const PdfTextExtractParams& params = { })
const;
158 Rect GetRect()
const;
160 Rect GetRectRaw()
const override;
162 void SetRect(
const Rect& rect);
164 void SetRectRaw(
const Rect& rect);
166 bool HasRotation(
double& teta)
const override;
171 void SetMediaBox(
const Rect& rect,
bool raw =
false);
176 void SetCropBox(
const Rect& rect,
bool raw =
false);
181 void SetTrimBox(
const Rect& rect,
bool raw =
false);
186 void SetBleedBox(
const Rect& rect,
bool raw =
false);
191 void SetArtBox(
const Rect& rect,
bool raw =
false);
198 unsigned GetPageNumber()
const;
207 static Rect CreateStandardPageSize(
const PdfPageSize pageSize,
bool landscape =
false);
212 Rect GetMediaBox(
bool raw =
false)
const;
217 Rect GetCropBox(
bool raw =
false)
const;
222 Rect GetTrimBox(
bool raw =
false)
const;
227 Rect GetBleedBox(
bool raw =
false)
const;
232 Rect GetArtBox(
bool raw =
false)
const;
237 unsigned GetRotation()
const;
242 double GetRotationRaw()
const;
248 void SetRotation(
int rotation);
252 bool MoveTo(
unsigned index);
254 template <
typename TField>
255 TField& CreateField(
const std::string_view& name,
const Rect& rect,
bool rawRect =
false);
257 PdfField& CreateField(
const std::string_view& name,
PdfFieldType fieldType,
const Rect& rect,
bool rawRect =
false);
263 PdfPageFieldIterable GetFieldsIterator();
264 PdfPageConstFieldIterable GetFieldsIterator()
const;
267 unsigned GetIndex()
const {
return m_Index; }
270 inline const PdfContents* GetContents()
const {
return m_Contents.get(); }
271 inline PdfContents* GetContents() {
return m_Contents.get(); }
274 inline const PdfResources* GetResources()
const {
return m_Resources.get(); }
275 inline PdfResources* GetResources() {
return m_Resources.get(); }
278 inline PdfAnnotationCollection& GetAnnotations() {
return m_Annotations; }
279 inline const PdfAnnotationCollection& GetAnnotations()
const {
return m_Annotations; }
283 void FlattenStructure();
284 void SetIndex(
unsigned index) { m_Index = index; }
286 void EnsureResourcesCreated()
override;
288 void CopyContentsTo(
OutputStream& stream)
const override;
290 PdfObjectStream& GetOrCreateContentsStream(PdfStreamAppendFlags flags)
override;
298 PdfDictionaryElement& getElement()
override;
300 PdfObject* findInheritableAttribute(
const std::string_view& name)
const;
302 PdfObject* findInheritableAttribute(
const std::string_view& name,
bool& isShallow)
const;
310 void initNewPage(
const Rect& size);
312 void ensureContentsCreated();
313 void ensureResourcesCreated();
319 Rect getPageBox(
const std::string_view& inBox,
bool isInheritable,
bool raw)
const;
321 void setPageBox(
const PdfName& inBox,
const Rect& rect,
bool raw);
327 const PdfElement& GetElement()
const =
delete;
329 const PdfObject* GetContentsObject()
const =
delete;
333 std::vector<PdfObject*> m_parents;
334 std::unique_ptr<PdfContents> m_Contents;
335 std::unique_ptr<PdfResources> m_Resources;
336 PdfAnnotationCollection m_Annotations;
340 template<
typename TField>
341 TField& PdfPage::CreateField(
const std::string_view& name,
const Rect & rect,
bool rawRect)
343 return static_cast<TField&
>(CreateField(name, PdfField::GetFieldType<TField>(), rect, rawRect));
346 template<
typename TField>
347 typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::begin()
const
349 if (m_page ==
nullptr)
352 return Iterator(m_page->GetAnnotations().begin(), m_page->GetAnnotations().end());
355 template<
typename TField>
356 typename PdfPageFieldIterableBase<TField>::Iterator PdfPageFieldIterableBase<TField>::end()
const
358 if (m_page ==
nullptr)
361 return Iterator(m_page->GetAnnotations().end(), m_page->GetAnnotations().end());
364 template<
typename TField>
365 void PdfPageFieldIterableBase<TField>::Iterator::stepIntoPageAnnot()
369 if (m_annotsIterator == m_annotsEnd)
372 auto& annot = **m_annotsIterator;
373 PdfField* field =
nullptr;
374 if (annot.GetType() == PdfAnnotationType::Widget &&
375 (field = &
static_cast<PdfAnnotationWidget&
>(annot).GetField(),
376 m_visitedObjs.find(field->GetObject().GetIndirectReference()) == m_visitedObjs.end()))
379 m_visitedObjs.insert(field->GetObject().GetIndirectReference());
387 m_visitedObjs.clear();
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
An interface for writing blocks of data to a data source.
Definition: OutputStream.h:18
A interface that provides the necessary features for a painter to draw onto a PdfObject.
Definition: PdfCanvas.h:28
A interface that provides a wrapper around "PDF content" - the instructions that are used to draw on ...
Definition: PdfContents.h:20
PdfDocument is the core interface for working with PDF documents.
Definition: PdfDocument.h:108
PdfElement is a common base class for all elements in a PDF file.
Definition: PdfElement.h:30
This class represents a PdfName.
Definition: PdfName.h:24
A PDF stream can be appended to any PdfObject and can contain arbitrary data.
Definition: PdfObjectStream.h:87
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:127
A interface that provides a wrapper around /Resources.
Definition: PdfResources.h:25
A rectangle defined by position and size.
Definition: Rect.h:20
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:479
PdfFieldType
The type of PDF field.
Definition: PdfDeclarations.h:614
PdfTextExtractFlags
Definition: PdfDeclarations.h:170