-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfconverter.cpp
More file actions
43 lines (35 loc) · 1.39 KB
/
Copy pathpdfconverter.cpp
File metadata and controls
43 lines (35 loc) · 1.39 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
#include "pdfconverter.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QProcess>
#include <QMessageBox>
#include <QLabel>
PDFConverter::PDFConverter(QWidget *parent) : QWidget(parent) {
auto *layout = new QVBoxLayout(this);
label = new QLabel("Chuyển đổi PDF sang Word (.docx)", this);
label->setAlignment(Qt::AlignCenter);
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);
}
void PDFConverter::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;
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.");
}
}