[Add] Implented async file splitting to multiple single page pdfs
This commit is contained in:
parent
9d1e82deb4
commit
0cbe75daac
@ -8,17 +8,57 @@ PDFJam::PDFJam(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFJam::run(void) {
|
/* Ensure the folder exists. */
|
||||||
#if 0
|
void PDFJam::makeFolder(QString path) {
|
||||||
if((pid = fork()) < 0) {
|
QString tmp = "mkdir -p %1";
|
||||||
|
int value = system(tmp.arg(path).toStdString().c_str());
|
||||||
}
|
if(value != 0)
|
||||||
else if(pid > 0) {
|
qDebug() << "ERROR: Failed to make " << path;
|
||||||
/* Parent. */
|
}
|
||||||
} else {
|
|
||||||
/* Child. */
|
void PDFJam::pushCommand(QString cmd) {
|
||||||
system("echo 'tata' > /tmp/test.txt");
|
mutex.lock();
|
||||||
}
|
cmdQueue.push_back(cmd);
|
||||||
#endif
|
mutex.unlock();
|
||||||
|
if(!isRunning()) start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFJam::loadFile(QString fileName, int fileNum, int numPages) {
|
||||||
|
QString path = "/tmp/hpdf/%1/";
|
||||||
|
path = path.arg(QString::number(fileNum));
|
||||||
|
makeFolder(path);
|
||||||
|
|
||||||
|
QString tmp = "pdfjam %1 %2 -- outfile %3%4.pdf";
|
||||||
|
QString cmd = "";
|
||||||
|
for(int i = 1; i <= numPages; i++) {
|
||||||
|
cmd += tmp.arg(fileName).arg(QString::number(i)).arg(path).arg(QString::number(i)) + ";";
|
||||||
|
}
|
||||||
|
pushCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PDFJam::nextCommand(void) {
|
||||||
|
QString cmd;
|
||||||
|
mutex.lock();
|
||||||
|
cmd = cmdQueue.first();
|
||||||
|
cmdQueue.pop_front();
|
||||||
|
mutex.unlock();
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PDFJam::isQueueEmpty(void) {
|
||||||
|
return (cmdQueue.size()==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFJam::run(void) {
|
||||||
|
while(!isQueueEmpty()) {
|
||||||
|
QString cmd = nextCommand();
|
||||||
|
int value = system(cmd.toStdString().c_str());
|
||||||
|
if(value != 0)
|
||||||
|
qDebug() << "ERROR: Failed to execute " << cmd;
|
||||||
|
else
|
||||||
|
qDebug() << "SUCCESS: executed " << cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*system("echo 'tata' > /tmp/test.txt");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,28 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <QThread>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <poppler-qt5.h>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
class PDFJam { /*:public QThread {*/
|
class PDFPageWidget;
|
||||||
|
class QImage;
|
||||||
|
|
||||||
|
class PDFJam : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PDFJam(void);
|
PDFJam(void);
|
||||||
|
|
||||||
|
void pushCommand(QString);
|
||||||
|
void loadFile(QString fileName, int, int);
|
||||||
|
void makeFolder(QString);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run(void);
|
void run(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
volatile bool stopped;
|
QVector<QString> cmdQueue;
|
||||||
|
QString nextCommand();
|
||||||
|
bool isQueueEmpty();
|
||||||
|
QMutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,21 +12,20 @@ void PDFPreviewWidget::setImage(QImage image) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PDFPreviewWidget::regenImage(void) {
|
void PDFPreviewWidget::regenImage(void) {
|
||||||
if(pPage != NULL) {
|
double dpi;
|
||||||
double dpi;
|
double dpi2;
|
||||||
double dpi2;
|
QSize targetSize = this->size();
|
||||||
QSize targetSize = this->size();
|
QSizeF oriSize = pPage->pageSizeF();
|
||||||
QSizeF oriSize = pPage->pageSizeF();
|
double oriDpi = 72;
|
||||||
double oriDpi = 72;
|
dpi = targetSize.height() / (float)oriSize.height()*72;
|
||||||
dpi = targetSize.height() / (float)oriSize.height()*72;
|
dpi2 = targetSize.width() / (float)oriSize.width()*72;
|
||||||
dpi2 = targetSize.width() / (float)oriSize.width()*72;
|
dpi = dpi<dpi2?dpi:dpi2;
|
||||||
dpi = dpi<dpi2?dpi:dpi2;
|
previewImage = pPage->renderToImage(dpi, dpi);
|
||||||
previewImage = pPage->renderToImage(dpi, dpi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFPreviewWidget::previewUpdate(Poppler::Page* pp) {
|
void PDFPreviewWidget::previewUpdate(Poppler::Page* pp) {
|
||||||
pPage = pp;
|
pPage = pp;
|
||||||
|
qDebug() << "Set new popler page" << pp;
|
||||||
regenImage();
|
regenImage();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -36,7 +35,8 @@ void PDFPreviewWidget::pageClicked(QMouseEvent* mouseEvent, QImage image) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PDFPreviewWidget::resizeEvent(QResizeEvent* event) {
|
void PDFPreviewWidget::resizeEvent(QResizeEvent* event) {
|
||||||
regenImage();
|
if(pPage != NULL)
|
||||||
|
regenImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFPreviewWidget::paintEvent(QPaintEvent* event) {
|
void PDFPreviewWidget::paintEvent(QPaintEvent* event) {
|
||||||
|
@ -39,6 +39,7 @@ void PDFTableWidget::loadFile(QString fileName) {
|
|||||||
PDFFileWidget* fileWidget = new PDFFileWidget();
|
PDFFileWidget* fileWidget = new PDFFileWidget();
|
||||||
fileWidget->setAncestor(this);
|
fileWidget->setAncestor(this);
|
||||||
fileWidget->setDocument(doc, fileName);
|
fileWidget->setDocument(doc, fileName);
|
||||||
|
pdfJam.loadFile(fileName, files.size()-1, doc->numPages());
|
||||||
connect(fileWidget, SIGNAL(pageClicked(QMouseEvent*,QImage)), this,
|
connect(fileWidget, SIGNAL(pageClicked(QMouseEvent*,QImage)), this,
|
||||||
SIGNAL(pageClicked(QMouseEvent*,QImage)));
|
SIGNAL(pageClicked(QMouseEvent*,QImage)));
|
||||||
connect(fileWidget, SIGNAL(previewUpdate(Poppler::Page*)), this,
|
connect(fileWidget, SIGNAL(previewUpdate(Poppler::Page*)), this,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <poppler-qt5.h>
|
#include <poppler-qt5.h>
|
||||||
|
#include "pdf_jam.h"
|
||||||
|
|
||||||
class QImage;
|
class QImage;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
@ -16,6 +17,7 @@ public:
|
|||||||
void loadFile(QString fileName);
|
void loadFile(QString fileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
PDFJam pdfJam;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* outerLayout;
|
QVBoxLayout* outerLayout;
|
||||||
|
Loading…
Reference in New Issue
Block a user