[Add] Added remove, rotate and export.

This commit is contained in:
Rtch90 2014-12-19 11:28:55 +00:00
parent 3744e8424d
commit 7af6a60e5c
2 changed files with 52 additions and 6 deletions

View File

@ -23,15 +23,60 @@ void PDFJam::pushCommand(QString cmd) {
if(!isRunning()) start(); if(!isRunning()) start();
} }
void PDFJam::loadFile(QString fileName, int fileNum, int numPages) { /* Rotate PDF page clockwise. */
bool PDFJam::rotatePage(int fileIndex, int rotatedPageIndex, int degree) {
if((degree != 90) && (degree != 180) && (degree != 270)) {
return false;
}
QString rtTmp = "pdf%1 /tmp/hpdf/%2/%3.pdf -- outfile /tmp/hpdf/%4/%5.pdf ";
QString cmd = rtTmp.arg(QString::number(degree)).arg(QString::number(fileIndex))
.arg(QString::number(rotatedPageIndex)).arg(QString::number(fileIndex))
.arg(QString::number(rotatedPageIndex));
pushCommand(cmd);
}
/* Remove page in a pdf file. */
bool PDFJam::removePage(int fileIndex, int numPages, int deletedPageIndex) {
if((deletedPageIndex < 0) || (deletedPageIndex >= numPages)) {
return false;
}
/*QString tmp = "file1.pdf '-' file2.pdf '1,2' file3.pdf '2-2' --outfile output.pdf"*/
QString rmTmp = "rm /tmp/hpdf/%1/%2.pdf ";
QString cmd = rmTmp.arg(QString::number(fileIndex)).arg(QString::number(deletedPageIndex));
QString tmp = "mv /tmp/hpdf/%1/%2.pdf /tmp/hpdf/%3/%4.pdf ";
for(int i = deletedPageIndex+1; i < numPages; i++) {
cmd += "&& " + tmp.arg(QString::number(fileIndex)).arg(QString::number(i))
.arg(QString::number(fileIndex)).arg(QString::number(i-1));
}
pushCommand(cmd);
}
/* Export file number 'fileIndex' to destination. */
void PDFJam::exportFile(int fileIndex, int numPages, QString dst) {
QString cmd = "pdfjam ";
QString tmp = "/tmp/hpdf/%1/%2.pdf '-' ";
for(int i = 0; i < numPages; i++) {
cmd += tmp.arg(QString::number(fileIndex)).arg(QString::number(i));
}
QString outTmp = "--outfile %1";
cmd += outTmp.arg(dst);
pushCommand(cmd);
}
void PDFJam::loadFile(QString fileName, int fileIndex, int numPages) {
QString path = "/tmp/hpdf/%1/"; QString path = "/tmp/hpdf/%1/";
path = path.arg(QString::number(fileNum)); path = path.arg(QString::number(fileIndex));
makeFolder(path); makeFolder(path);
QString tmp = "pdfjam %1 %2 -- outfile %3%4.pdf"; QString tmp = "pdfjam %1 %2 -- outfile %3%4.pdf";
QString cmd = ""; QString cmd = "";
for(int i = 1; i <= numPages; i++) { for(int i = 0; i <= numPages; i++) {
cmd += tmp.arg(fileName).arg(QString::number(i)).arg(path).arg(QString::number(i)) + ";"; cmd += tmp.arg(fileName).arg(QString::number(i+1)).arg(path).arg(QString::number(i)) + ";";
} }
pushCommand(cmd); pushCommand(cmd);
} }
@ -58,7 +103,5 @@ void PDFJam::run(void) {
else else
qDebug() << "SUCCESS: executed " << cmd;*/ qDebug() << "SUCCESS: executed " << cmd;*/
} }
/*system("echo 'tata' > /tmp/test.txt");*/
} }

View File

@ -14,6 +14,9 @@ public:
void pushCommand(QString); void pushCommand(QString);
void loadFile(QString fileName, int, int); void loadFile(QString fileName, int, int);
void exportFile(int, int, QString);
bool removePage(int, int, int);
bool rotatePage(int, int, int);
void makeFolder(QString); void makeFolder(QString);
protected: protected: