[Add] rotate, export with nup, 2 side offset and page remove.

This commit is contained in:
Rtch90 2014-12-19 12:53:11 +00:00
parent 7af6a60e5c
commit a4b88ab1ff
4 changed files with 50 additions and 11 deletions

View File

@ -9,4 +9,6 @@
-I /usr/include/gtk-3.0/
-I /usr/include/qt4/
-I /usr/include/x86_64-linux-gnu/qt5/
-I /usr/include/x86_64-linux-gnu/qt5/QtWidgets/
-I /usr/local/Qt-5.3.2/lib/
-I lib/lua/

View File

@ -29,7 +29,7 @@ bool PDFJam::rotatePage(int fileIndex, int rotatedPageIndex, int degree) {
return false;
}
QString rtTmp = "pdf%1 /tmp/hpdf/%2/%3.pdf -- outfile /tmp/hpdf/%4/%5.pdf ";
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));
@ -54,8 +54,21 @@ bool PDFJam::removePage(int fileIndex, int numPages, int deletedPageIndex) {
pushCommand(cmd);
}
void PDFJam::movePage(int fromFileIndex, int fromPageIndex, int toFileIndex, int toPageIndex) {
}
void PDFJam::savePageAsImage(Poppler::Page pp, QString dst, double dpi = 72) {
}
/* Export file number 'fileIndex' to destination. */
void PDFJam::exportFile(int fileIndex, int numPages, QString dst) {
/* Supported n-up, orientation, offset options. */
void PDFJam::exportFile(int fileIndex, int numPages, QString dst,
QSize nup = QSize(1,1), bool isLandscape = false, bool hasTwoSideOffset = false,
int leftOffset = 0, int rightOffset = 0) {
QString cmd = "pdfjam ";
QString tmp = "/tmp/hpdf/%1/%2.pdf '-' ";
@ -63,22 +76,43 @@ void PDFJam::exportFile(int fileIndex, int numPages, QString dst) {
cmd += tmp.arg(QString::number(fileIndex)).arg(QString::number(i));
}
QString outTmp = "--outfile %1";
QString orientation = isLandscape?" --landscape ": " --no-landscape ";
cmd = orientation;
if((nup.width() == 1) || (nup.height() != 1)) {
QString nupTmp = " --nup '%1x%1' --frame true ";
cmd += nupTmp.arg(QString::number(nup.width())).arg(QString::number(nup.height()));
}
QString outTmp = " --outfile %1 ";
cmd += outTmp.arg(dst);
pushCommand(cmd);
/* Offset comes next. */
}
void PDFJam::loadFile(QString fileName, int fileIndex, int numPages) {
void PDFJam::loadFile(QString fileName, int fileIndex, Poppler::Document* pd) {
int numPages = pd->numPages();
QString path = "/tmp/hpdf/%1/";
path = path.arg(QString::number(fileIndex));
makeFolder(path);
QString tmp = "pdfjam %1 %2 -- outfile %3%4.pdf";
QString tmp = "pdfjam %1 %2 --outfile %3%4.pdf %5";
QString cmd = "";
for(int i = 0; i <= numPages; i++) {
cmd += tmp.arg(fileName).arg(QString::number(i+1)).arg(path).arg(QString::number(i)) + ";";
QString orientation = " --no-landscape ";
QSizeF pageSize = pd->page(i)->pageSizeF();
if(pageSize.width() > pageSize.height()) {
orientation = " --landscape ";
}
cmd += tmp.arg(fileName).arg(QString::number(i+1)).arg(path)
.arg(QString::number(i)).arg(orientation) + " ; ";
}
pushCommand(cmd);
/* Test the backend functions. */
/*removePage(0, numPages, 5);
rotatePage(0, 5, 270);
exportFile(0, numPages-1, "/home/allanis/conco.pdf", QSize(2, 2), true, true, 1, 0);*/
/* End test. */
}
QString PDFJam::nextCommand(void) {
@ -98,10 +132,10 @@ void PDFJam::run(void) {
while(!isQueueEmpty()) {
QString cmd = nextCommand();
int value = system(cmd.toStdString().c_str());
/*if(value != 0)
if(value != 0)
qDebug() << "ERROR: Failed to execute " << cmd;
else
qDebug() << "SUCCESS: executed " << cmd;*/
qDebug() << "SUCCESS: executed " << cmd;
}
}

View File

@ -13,8 +13,11 @@ public:
PDFJam(void);
void pushCommand(QString);
void loadFile(QString fileName, int, int);
void exportFile(int, int, QString);
void loadFile(QString fileName, int, Poppler::Document*);
void exportFile(int, int, QString, QSize, bool, bool, int, int);
void savePageAsImage(Poppler::Page pp, QString dst, double);
void movePage(int fromFileIndex, int fromPageIndex, int toFileIndex, int toPageIndex);
bool removePage(int, int, int);
bool rotatePage(int, int, int);
void makeFolder(QString);

View File

@ -41,7 +41,7 @@ void PDFTableWidget::loadFile(QString fileName) {
PDFFileWidget* fileWidget = new PDFFileWidget();
fileWidget->setAncestor(this);
fileWidget->setDocument(doc, fileName);
pdfJam.loadFile(fileName, files.size()-1, doc->numPages());
pdfJam.loadFile(fileName, files.size()-1, doc);
fileWidgets.append(fileWidget);