-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.cpp
More file actions
60 lines (49 loc) · 1.81 KB
/
Copy pathapi.cpp
File metadata and controls
60 lines (49 loc) · 1.81 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
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QProcess>
#include <QMessageBox>
#include <QLabel>
class PDFConverter : public QWidget {
Q_OBJECT
public:
PDFConverter(QWidget *parent = nullptr) : QWidget(parent) {
auto *layout = new QVBoxLayout(this);
auto *label = new QLabel("Chuyển đổi PDF sang Word (.docx)", this);
label->setAlignment(Qt::AlignCenter);
auto *selectButton = new QPushButton("Chọn file PDF", this);
connect(selectButton, &QPushButton::clicked, this, &PDFConverter::convertPDF);
layout->addWidget(label);
layout->addWidget(selectButton);
setLayout(layout);
setWindowTitle("PDF to Word Converter");
resize(300, 150);
}
private slots:
void convertPDF() {
QString pdfFile = QFileDialog::getOpenFileName(this, "Chọn file PDF", "", "PDF Files (*.pdf)");
if (pdfFile.isEmpty()) return;
QString outputDir = QFileDialog::getExistingDirectory(this, "Chọn thư mục xuất");
if (outputDir.isEmpty()) return;
// Gọi LibreOffice CLI để chuyển đổi PDF sang DOCX
QProcess process;
QStringList args;
args << "--headless" << "--convert-to" << "docx" << "--outdir" << outputDir << pdfFile;
process.start("soffice", args);
process.waitForFinished();
if (process.exitCode() == 0) {
QMessageBox::information(this, "Thành công", "Đã chuyển đổi thành công!");
} else {
QMessageBox::critical(this, "Lỗi", "Không thể chuyển đổi PDF.");
}
}
};
#include "main.moc"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
PDFConverter window;
window.show();
return app.exec();
}