Implement pdfPages with madness

This commit is contained in:
Anton Thomasson 2021-11-20 17:21:46 +01:00
parent 7e528ca2bd
commit 2d521dcbae
2 changed files with 19 additions and 4 deletions

View file

@ -1,9 +1,12 @@
#include <poppler/glib/poppler.h>
#include <poppler/glib/poppler-document.h>
#include "convertchecker.h"
#include <QProcess>
#include <QtDebug>
#include "mimer.h"
ConvertChecker::ConvertChecker()
ConvertChecker::ConvertChecker() : poppler("libpoppler-glib.so.8")
{
_pdf = true;
_calligra = false;
@ -44,7 +47,17 @@ ConvertChecker* ConvertChecker::instance()
return m_Instance;
}
quint32 ConvertChecker::pdfPages(QString /*filename*/)
int ConvertChecker::pdfPages(QString filename)
{
return 0;
FUNC(poppler, PopplerDocument*, poppler_document_new_from_file, const char*, const char*, GError**);
FUNC(poppler, int, poppler_document_get_n_pages, PopplerDocument*);
std::string url("file://");
url.append(filename.toStdString());
GError* error = nullptr;
PopplerDocument* doc = poppler_document_new_from_file(url.c_str(), nullptr, &error);
int pages = poppler_document_get_n_pages(doc);
g_object_unref(doc);
return pages;
}

View file

@ -2,6 +2,7 @@
#define CONVERTCHECKER_H
#include <QObject>
#include <QMutex>
#include "madness.h"
class ConvertChecker : public QObject
{
@ -11,7 +12,7 @@ public:
Q_PROPERTY(bool pdf MEMBER _pdf CONSTANT)
Q_PROPERTY(bool calligra MEMBER _calligra CONSTANT)
Q_INVOKABLE quint32 pdfPages(QString pdf);
Q_INVOKABLE int pdfPages(QString pdf);
signals:
protected:
@ -23,6 +24,7 @@ private:
ConvertChecker(const ConvertChecker &);
ConvertChecker& operator=(const ConvertChecker &);
LibLoader poppler;
bool _pdf;
bool _calligra;
};