read and show pdf file

This commit is contained in:
Marc Wäckerlin
2015-11-10 22:56:43 +00:00
parent a4e5b55c16
commit 74847cd624
9 changed files with 81 additions and 18 deletions

View File

@@ -19,7 +19,7 @@ int main(int argc, char *argv[]) try {
parser.addHelpOption();
parser.process(a);
QStringList scripts(parser.positionalArguments());
Pdfsign w;
PdfSign w;
w.show();
return a.exec();
} catch (std::exception &x) {

View File

@@ -55,14 +55,16 @@ pdfsign_TR_FILES = main.cxx version.cxx
pdfsign_SOURCES = ${pdfsign_TR_FILES} ${BUILT_SOURCES}
## automatic assembly, no need to change
BUILT_SOURCES = ${pdfsign_MOCFILES} ${pdfsign_UIFILES} ${pdfsign_TRANSLATIONS} ${pdfsign_RESOURCES}
BUILT_SOURCES = ${pdfsign_MOCFILES} ${pdfsign_UIFILES} \
${pdfsign_TRANSLATIONS} ${pdfsign_RESOURCES}
## automatic assembly, no need to change
EXTRA_DIST_TR = ${pdfsign_MOCFILES:moc_%.cxx=%.hxx} ${pdfsign_UIFILES:ui_%.hxx=%.ui}
EXTRA_DIST_TR = ${pdfsign_MOCFILES:moc_%.cxx=%.hxx} ${pdfsign_UIFILES:ui_%.hxx=%.ui}
## automatic assembly, no need to change
## except: adapt the pre-delivered qt_%.qm list (language files you copy from qt
EXTRA_DIST = ${EXTRA_DIST_TR} ${pdfsign_RESOURCES:qrc_%.cxx:%.qrc} ${pdfsign_TRANSLATIONS:%.qm=%.ts} qt_de.qm qt_fr.qm
EXTRA_DIST = ${EXTRA_DIST_TR} ${pdfsign_RESOURCES:qrc_%.cxx:%.qrc} \
${pdfsign_TRANSLATIONS:%.qm=%.ts} qt_de.qm qt_fr.qm
## automatic assembly, no need to change
LANGUAGE_FILES = ${EXTRA_DIST_TR} ${pdfsign_TR_FILES}

View File

@@ -13,16 +13,37 @@
#include <QMainWindow>
#include <ui_pdfsign.hxx>
#include <poppler/qt5/poppler-qt5.h>
#include <QFileDialog>
#include <memory>
/// Main Window
/** Main window for pdfsign */
class Pdfsign: public QMainWindow, protected Ui::Pdfsign {
class PdfSign: public QMainWindow, protected Ui::Pdfsign {
Q_OBJECT;
public:
explicit Pdfsign(QWidget *parent = 0): QMainWindow(parent) {
explicit PdfSign(QWidget *parent = 0): QMainWindow(parent) {
setupUi(this);
}
virtual ~Pdfsign() {}
virtual ~PdfSign() {}
public slots:
void on_actionOpen_triggered() {
QString fileName(QFileDialog::getOpenFileName(this, tr("Open PDF File"), QString(),
tr("PDF-Document (*.pdf)")));
if (fileName.isEmpty()) return;
_pdf = std::shared_ptr<Poppler::Document>(Poppler::Document::load(fileName));
showPage();
}
public:
void showPage(int pageNumber=0) {
if (!_pdf) return;
std::shared_ptr<Poppler::Page> pdfPage(_pdf->page(pageNumber));
if (!pdfPage) return;
_pdfDisplay->setPixmap(QPixmap::fromImage(pdfPage->renderToImage()));
return;
}
private:
std::shared_ptr<Poppler::Document> _pdf;
};
#endif

View File

@@ -13,18 +13,40 @@
<property name="windowTitle">
<string>Pdfsign</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="_pdfDisplay">
<property name="text">
<string>PDF-Document</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="actionOpen"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionOpen">
<property name="text">
<string>&amp;Open...</string>
</property>
</action>
</widget>
<resources/>
<connections/>