Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Pdf
Pdf.cpp
Go to the documentation of this file.
1
/******************************************************************************************************
2
* (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3
* under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4
* LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5
******************************************************************************************************/
6
7
#include "
DlgImportCroppingPdf.h
"
8
#include "
ImportCroppingUtilPdf.h
"
9
#include "
Pdf.h
"
10
#include "poppler-qt6.h"
11
#include <QApplication>
12
#include <QImage>
13
#include <QString>
14
15
using namespace
Poppler
;
16
17
const
int
X_TOP_LEFT
= 0,
Y_TOP_LEFT
= 0;
18
const
int
WIDTH
= -1,
HEIGHT
= -1;
// Negative values give full page
19
const
int
FIRST_PAGE_1_BASED
= 1;
20
21
Pdf::Pdf
()
22
{
23
}
24
25
PdfReturn
Pdf::load
(
const
QString &fileName,
26
QImage &image,
27
int
resolution,
28
ImportCropping
importCropping,
29
bool
isErrorReportRegressionTest)
const
30
{
31
std::unique_ptr<Document> document;
32
33
ImportCroppingUtilPdf
importCroppingUtil;
34
bool
cropping = importCroppingUtil.
applyImportCropping
(isErrorReportRegressionTest,
35
fileName,
36
importCropping,
37
document);
38
39
PdfReturn
rtn;
40
QApplication::setOverrideCursor(Qt::BusyCursor);
// Since loading can be slow
41
if
(cropping) {
42
43
rtn = loadWithCropping (std::move(document),
44
image,
45
resolution);
46
47
}
else
{
48
49
rtn = loadWithoutCropping (fileName,
50
image,
51
resolution);
52
53
}
54
QApplication::restoreOverrideCursor();
55
56
return
rtn;
57
}
58
59
PdfReturn
Pdf::loadWithCropping (std::unique_ptr<Document> document,
60
QImage &image,
61
int
resolution)
const
62
{
63
PdfReturn
pdfReturn =
PDF_RETURN_FAILED
;
64
65
// Get page and extent. At this point it is always true that the image can be read
66
DlgImportCroppingPdf
dlg (*document,
67
resolution);
68
if
(dlg.exec() == QDialog::Accepted) {
69
70
// Returned image is null if it could not be read
71
image = dlg.image ();
72
73
if
(!image.isNull()) {
74
pdfReturn =
PDF_RETURN_SUCCESS
;
75
}
76
77
}
else
{
78
pdfReturn =
PDF_RETURN_CANCELED
;
79
}
80
81
return
pdfReturn;
82
}
83
84
PdfReturn
Pdf::loadWithoutCropping (
const
QString &fileName,
85
QImage &image,
86
int
resolution)
const
87
{
88
PdfReturn
pdfReturn =
PDF_RETURN_FAILED
;
89
90
// Simple check to prevent complaints from poppler code
91
if
(fileName.right (4).toLower () ==
".pdf"
) {
92
93
// Try to read the file
94
std::unique_ptr<Document> document = Document::load (fileName);
95
96
if
(document !=
nullptr
) {
97
if
(!document->isLocked ()) {
98
99
std::unique_ptr<Page> page = document->page (
FIRST_PAGE_1_BASED
- 1);
100
if
(page !=
nullptr
) {
101
102
image = page->renderToImage (resolution,
103
resolution,
104
X_TOP_LEFT
,
105
Y_TOP_LEFT
,
106
WIDTH
,
107
HEIGHT
);
108
109
if
(!image.isNull()) {
110
pdfReturn =
PDF_RETURN_SUCCESS
;
111
}
112
}
113
}
114
}
115
}
116
117
return
pdfReturn;
118
}
X_TOP_LEFT
const int X_TOP_LEFT
Definition
DlgImportCroppingPdf.cpp:31
WIDTH
const int WIDTH
Definition
DlgImportCroppingPdf.cpp:32
FIRST_PAGE_1_BASED
const int FIRST_PAGE_1_BASED
Definition
DlgImportCroppingPdf.cpp:33
HEIGHT
const int HEIGHT
Definition
DlgImportCroppingPdf.cpp:32
Y_TOP_LEFT
const int Y_TOP_LEFT
Definition
DlgImportCroppingPdf.cpp:31
DlgImportCroppingPdf.h
ImportCroppingUtilPdf.h
ImportCropping
ImportCropping
Definition
ImportCropping.h:11
Pdf.h
PdfReturn
PdfReturn
Return values from load operation.
Definition
Pdf.h:20
PDF_RETURN_FAILED
@ PDF_RETURN_FAILED
Definition
Pdf.h:22
PDF_RETURN_CANCELED
@ PDF_RETURN_CANCELED
Definition
Pdf.h:21
PDF_RETURN_SUCCESS
@ PDF_RETURN_SUCCESS
Definition
Pdf.h:23
DlgImportCroppingPdf
Dialog for selecting a page and frame on that page when importing an image from a pdf file.
Definition
DlgImportCroppingPdf.h:29
ImportCroppingUtilPdf
Import of pdf files.
Definition
ImportCroppingUtilPdf.h:21
ImportCroppingUtilPdf::applyImportCropping
bool applyImportCropping(bool isRegression, const QString &fileName, ImportCropping importCropping, std::unique_ptr< Poppler::Document > &document) const
For pdf files, skip cropping dialog during regression testing, otherwise crop if it is always turned ...
Definition
ImportCroppingUtilPdf.cpp:17
Pdf::Pdf
Pdf()
Single constructor.
Definition
Pdf.cpp:21
Pdf::load
PdfReturn load(const QString &fileName, QImage &image, int resolution, ImportCropping importCropping, bool isErrorReportRegressionTest) const
Try to load the specified file. Success is indicated in the function return value.
Definition
Pdf.cpp:25
Poppler
Definition
DlgImportCroppingPdf.h:14
Generated on
for Engauge Digitizer by
1.17.0