-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractor.cpp
More file actions
76 lines (66 loc) · 1.84 KB
/
extractor.cpp
File metadata and controls
76 lines (66 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "extractor.h"
extractor::extractor()
{
}
void extractor::load(QWidget * (t))
{
document->close();
filename = QFileDialog::getOpenFileName(t,
QObject::tr("Open PDF File"), "./", QObject::tr("PDF Files (*.pdf)"));
document->load(filename);
// pages count
pgcount = document->pageCount();
// bool on set
extracted = false;
}
void extractor::extr(int page)
{
allText = new QString;
if(checkboxc == true) {
readal();
} else {
*allText = document->getAllText(page).text();
}
// Removing special characters
format = new QString;
*format = allText->remove(QRegExp("[\\^$(){},>.:;*#_=<!+-/]+"));
std::string a = format->toStdString();
delete format;
// Takes only space separated C++ strings.
splitter(a);
// Conversion of Qlist to const to pump texedit
rawSliced = new QStringList;
*rawSliced = *templist;
delete templist;
// set da bool
extracted = true;
}
QStringList * extractor::splitter(string t)
{
stringstream ss(t);
string word;
templist = new QStringList;
while (ss >> word) {
QString str = QString::fromUtf8(word.c_str());
templist->append(str);
}
return templist;
}
void extractor::readal()
{
int pgcounts = document->pageCount();
selectedText = new QString;
for (int i = 0; i <= pgcounts ; i++ ) {
*selectedText = document->getAllText(i).text();
allText->append(*selectedText);
}
delete selectedText;
}
void extractor::save(QString text)
{
QString outputFile = QFileDialog::getSaveFileName(nullptr, "Save as", ".", "Docs (*.docx *.odf);;Text files (*.txt);;XML files (*.xml)" );
QFile Saved(outputFile);
Saved.open(QFile::WriteOnly | QFile::Truncate | QFile::Text);
QTextStream out(&Saved);
out << text;
}