KItinerary

pdfdocument.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10
11#include <KItinerary/PdfImage>
12
13#include <QDateTime>
14#include <QExplicitlySharedDataPointer>
15#include <QObject>
16#include <QVariant>
17
18#include <memory>
19
20
21namespace KItinerary {
22
23class PdfLink;
24class PdfPagePrivate;
25
26/** A page in a PDF document.
27 */
28class KITINERARY_EXPORT PdfPage
29{
30 Q_GADGET
31 Q_PROPERTY(QString text READ text)
32 Q_PROPERTY(QVariantList images READ imagesVariant)
33 Q_PROPERTY(QVariantList links READ linksVariant)
34 Q_PROPERTY(int width READ width)
35 Q_PROPERTY(int height READ height)
36public:
37 PdfPage();
38 PdfPage(const PdfPage&);
39 ~PdfPage();
40 PdfPage& operator=(const PdfPage&);
41
42 /** The entire text on this page. */
43 QString text() const;
44
45 /** Returns the text in the specified sub-rect of this page.
46 * All parameters are relative values between @c 0 and @c 1 of the entire page size.
47 */
48 Q_INVOKABLE QString textInRect(double left, double top, double right, double bottom) const;
49
50 /** The number of images found in this document. */
51 int imageCount() const;
52
53 /** The n-th image found in this document. */
54 PdfImage image(int index) const;
55
56 /** Returns the images in the specified sub-rect of this page.
57 * All parameters are relative values between @c 0 and @c 1 of the entire page size.
58 */
59 Q_INVOKABLE QVariantList imagesInRect(double left, double top, double right, double bottom) const;
60
61 /** The number of links found in this document. */
62 int linkCount() const;
63
64 /** The n-th link found in this document. */
65 PdfLink link(int index) const;
66
67 /** Returns all links in the specified sub-rect of this page.
68 * All parameters are relative values between @c 0 and @c 1 of the entire page size.
69 * Links are sorted top to bottom / left to right based on their top left corner.
70 */
71 Q_INVOKABLE QVariantList linksInRect(double left, double top, double right, double bottom) const;
72
73 /** Page size in millimeters. */
74 int width() const;
75 int height() const;
76
77private:
78 QVariantList imagesVariant() const;
79 QVariantList linksVariant() const;
80
81 friend class PdfDocument;
83};
84
85
86class PdfDocumentPrivate;
87
88/** PDF document for extraction.
89 * This is used as input for ExtractorEngine and the JS extractor scripts.
90 */
91class KITINERARY_EXPORT PdfDocument : public QObject
92{
93 Q_OBJECT
94 Q_PROPERTY(QString text READ text CONSTANT)
95 Q_PROPERTY(int pageCount READ pageCount CONSTANT)
96 Q_PROPERTY(QVariantList pages READ pagesVariant CONSTANT)
97 Q_PROPERTY(QDateTime creationTime READ creationTime CONSTANT)
98 Q_PROPERTY(QDateTime modificationTime READ modificationTime CONSTANT)
99 Q_PROPERTY(QString title READ title CONSTANT)
100 Q_PROPERTY(QString producer READ producer CONSTANT)
101 Q_PROPERTY(QString creator READ creator CONSTANT)
102 Q_PROPERTY(QString author READ author CONSTANT)
103
104public:
105 explicit PdfDocument(QObject *parent = nullptr);
106 ~PdfDocument();
107
108 /** The entire text extracted from the PDF document. */
109 QString text() const;
110
111 /** The number of pages in this document. */
112 int pageCount() const;
113
114 /** The n-thj page in this document. */
115 PdfPage page(int index) const;
116
117 /** File size of the entire document in bytes. */
118 int fileSize() const;
119
120 /** Creation time as specified in the PDF file. */
121 QDateTime creationTime() const;
122 /** Modification time as specified in the PDF file. */
123 QDateTime modificationTime() const;
124
125 /** The document title. */
126 QString title() const;
127 /** The document producer. */
128 QString producer() const;
129 /** The document creator. */
130 QString creator() const;
131 /** The document author. */
132 QString author() const;
133
134 /** Creates a PdfDocument from the given raw data.
135 * @returns @c nullptr if loading fails or Poppler was not found.
136 */
137 static PdfDocument* fromData(const QByteArray &data, QObject *parent = nullptr);
138
139 /** Fast check whether @p data might be a PDF document. */
140 static bool maybePdf(const QByteArray &data);
141
142private:
143 QVariantList pagesVariant() const;
144
145 std::unique_ptr<PdfDocumentPrivate> d;
146};
147
148}
PDF document for extraction.
Definition pdfdocument.h:92
An image in a PDF document.
Definition pdfimage.h:74
A page in a PDF document.
Definition pdfdocument.h:29
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:00:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.