-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdF2txt.cpp
More file actions
39 lines (28 loc) · 870 Bytes
/
PdF2txt.cpp
File metadata and controls
39 lines (28 loc) · 870 Bytes
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
#include <iostream>
#include <poppler-document.h>
#include <poppler-page.h>
int main() {
std::string pdfPath, textPath;
// Input PDF file path
std::cout << "Enter the PDF file path: ";
std::getline(std::cin, pdfPath);
// Input text file path
std::cout << "Enter the text file path: ";
std::getline(std::cin, textPath);
poppler::document* doc = poppler::document::load_from_file(pdfPath.c_str());
if (!doc) {
std::cerr << "Error loading PDF file.\n";
return 1;
}
std::string text;
for (int i = 0; i < doc->pages(); ++i) {
poppler::page* page = doc->create_page(i);
text += page->text().to_string();
}
delete doc;
std::ofstream textFile(textPath);
textFile << text;
textFile.close();
std::cout << "Text extracted and saved successfully.\n";
return 0;
}