From a4b88ab1ff8aebde9bf74ab0a44ef31eb53d9076 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Fri, 19 Dec 2014 12:53:11 +0000 Subject: [PATCH] [Add] rotate, export with nup, 2 side offset and page remove. --- .clang_complete | 2 ++ src/pdf_jam.cpp | 50 +++++++++++++++++++++++++++++++++------- src/pdf_jam.h | 7 ++++-- src/pdf_table_widget.cpp | 2 +- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/.clang_complete b/.clang_complete index 9093b49..209741d 100644 --- a/.clang_complete +++ b/.clang_complete @@ -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/ diff --git a/src/pdf_jam.cpp b/src/pdf_jam.cpp index 1db2bfd..61b49ae 100644 --- a/src/pdf_jam.cpp +++ b/src/pdf_jam.cpp @@ -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; } } diff --git a/src/pdf_jam.h b/src/pdf_jam.h index 5334985..1f1ba3b 100644 --- a/src/pdf_jam.h +++ b/src/pdf_jam.h @@ -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); diff --git a/src/pdf_table_widget.cpp b/src/pdf_table_widget.cpp index a0f820b..3f3d758 100644 --- a/src/pdf_table_widget.cpp +++ b/src/pdf_table_widget.cpp @@ -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);