You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
4.3 KiB
123 lines
4.3 KiB
14 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef __PLUGINFACTORY_HXX__
|
||
|
#define __PLUGINFACTORY_HXX__
|
||
|
|
||
|
#include <QtWebKit/QWebPluginFactory>
|
||
|
#include <poppler/qt4/poppler-qt4.h>
|
||
|
#include <pdfdisplay.hpp>
|
||
|
|
||
|
#include <QtCore/QDebug>
|
||
|
#ifndef LOG
|
||
|
#define LOG qDebug()<<__PRETTY_FUNCTION__
|
||
|
#endif
|
||
|
|
||
|
#define foreach(A, B) \
|
||
|
auto foreach_loopvar_##A(B); \
|
||
|
for (auto A(foreach_loopvar_##A.begin()); A!=foreach_loopvar_##A.end(); ++A)
|
||
|
|
||
|
class PluginFactory: public QWebPluginFactory {
|
||
|
public:
|
||
|
PluginFactory(QObject* p=0): QWebPluginFactory(p) {
|
||
|
LOG;
|
||
|
Plugin plugin;
|
||
|
plugin.name = "Show PDF-Document";
|
||
|
plugin.description = "Plugin for PDF documents";
|
||
|
MimeType mime;
|
||
|
mime.fileExtensions<<"pdf";
|
||
|
mime.name = "application/pdf";
|
||
|
mime.description = "PDF-Document";
|
||
|
plugin.mimeTypes<<mime;
|
||
|
_plugins.push_back(plugin);
|
||
|
}
|
||
|
virtual QObject* create(const QString& mimeType, const QUrl& url,
|
||
|
const QStringList& argumentNames,
|
||
|
const QStringList& argumentValues ) const {
|
||
|
LOG<<"mimeType:"<<mimeType
|
||
|
<<"url:"<<url
|
||
|
<<"argumentNames:"<<argumentNames.join(", ")
|
||
|
<<"argumentValues:"<<argumentValues.join(", ");
|
||
|
if (mimeType=="application/pdf") {
|
||
|
Poppler::Document *doc = Poppler::Document::load(url.path());
|
||
|
assert(doc);
|
||
|
assert(!doc->isLocked());
|
||
|
|
||
|
// output some meta-data
|
||
|
int major = 0, minor = 0;
|
||
|
doc->getPdfVersion( &major, &minor );
|
||
|
qDebug() << " PDF Version: " << qPrintable(QString::fromLatin1("%1.%2").arg(major).arg(minor));
|
||
|
qDebug() << " Title: " << doc->info("Title");
|
||
|
qDebug() << " Subject: " << doc->info("Subject");
|
||
|
qDebug() << " Author: " << doc->info("Author");
|
||
|
qDebug() << " Key words: " << doc->info("Keywords");
|
||
|
qDebug() << " Creator: " << doc->info("Creator");
|
||
|
qDebug() << " Producer: " << doc->info("Producer");
|
||
|
qDebug() << " Date created: " << doc->date("CreationDate").toString();
|
||
|
qDebug() << " Date modified: " << doc->date("ModDate").toString();
|
||
|
qDebug() << "Number of pages: " << doc->numPages();
|
||
|
qDebug() << " Linearised: " << doc->isLinearized();
|
||
|
qDebug() << " Encrypted: " << doc->isEncrypted();
|
||
|
qDebug() << " OK to print: " << doc->okToPrint();
|
||
|
qDebug() << " OK to copy: " << doc->okToCopy();
|
||
|
qDebug() << " OK to change: " << doc->okToChange();
|
||
|
qDebug() << "OK to add notes: " << doc->okToAddNotes();
|
||
|
qDebug() << " Page mode: " << doc->pageMode();
|
||
|
qDebug() << " Metadata: " << doc->metadata();
|
||
|
QStringList fontNameList;
|
||
|
foreach(font, doc->fonts())
|
||
|
fontNameList += font->name();
|
||
|
qDebug() << " Fonts: " << fontNameList.join( ", " );
|
||
|
|
||
|
if ( doc->hasEmbeddedFiles() ) {
|
||
|
qDebug() << "Embedded files:";
|
||
|
foreach(file, doc->embeddedFiles()) {
|
||
|
qDebug() << " " << (*file)->name();
|
||
|
}
|
||
|
qDebug();
|
||
|
} else {
|
||
|
qDebug() << "No embedded files";
|
||
|
}
|
||
|
|
||
|
if (doc->numPages() <= 0)
|
||
|
{
|
||
|
delete doc;
|
||
|
qDebug() << "Doc has no pages";
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
std::auto_ptr<Poppler::Page> page(doc->page(0));
|
||
|
qDebug() << "Page 1 size: " << page->pageSize().width()/72 << "inches x " << page->pageSize().height()/72 << "inches";
|
||
|
}
|
||
|
|
||
|
bool useArthur(false);
|
||
|
PDFDisplay* test(new PDFDisplay(doc, useArthur));
|
||
|
test->setWindowTitle("Poppler-Qt4 Test");
|
||
|
test->setShowTextRects(false);
|
||
|
test->display();
|
||
|
test->show();
|
||
|
// QMainWindow* main(new QMainWindow);
|
||
|
// main->setCentralWidget(test);
|
||
|
// main->show();
|
||
|
return test;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
virtual QList<Plugin> plugins() const {
|
||
|
LOG;
|
||
|
return _plugins;
|
||
|
}
|
||
|
virtual void refreshPlugins() {
|
||
|
LOG;
|
||
|
}
|
||
|
private:
|
||
|
QList<Plugin> _plugins;
|
||
|
};
|
||
|
|
||
|
#endif
|