int main( int argc, char **argv )
{
    QApplication a( argc, argv );               // QApplication required!

    QTime t;
    t.start();

    QDir directory( argv[1] );
    foreach ( const QString &fileName, directory.entryList() ) {
        if (fileName.endsWith("pdf") ) {
	    qDebug() << "Doing" << fileName.toLatin1().data() << ":";
	    Poppler::Document *doc = Poppler::Document::load( directory.canonicalPath()+"/"+fileName );
	    if (!doc) {
		qWarning() << "doc not loaded";
	    } else if ( doc->isLocked() ) {
	        if (! doc->unlock( "", "password" ) ) {
		    qWarning() << "couldn't unlock document";
		    delete doc;
		}
	    } else {
		doc->pdfVersion();
		doc->info("Title");
		doc->info("Subject");
		doc->info("Author");
		doc->info("Keywords");
		doc->info("Creator");
		doc->info("Producer");
		doc->date("CreationDate").toString();
		doc->date("ModDate").toString();
		doc->numPages();
		doc->isLinearized();
		doc->isEncrypted();
		doc->okToPrint();
		doc->okToCopy();
		doc->okToChange();
		doc->okToAddNotes();
		doc->pageMode();

		for( int index = 0; index < doc->numPages(); ++index ) {
		    Poppler::Page *page = doc->page( index );
		    QImage image = page->renderToImage();
		    page->pageSize();
		    page->orientation();
		    delete page;
		    std::cout << ".";
		    std::cout.flush();
		}
		std::cout << std::endl;
		delete doc;
	    }
	}
    }

    std::cout << "Elapsed time: " << (t.elapsed()/1000) << "seconds" << std::endl;

}
Exemplo n.º 2
0
void TestPassword::password3()
{
    Poppler::Document *doc;
    doc = Poppler::Document::load( QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncrypted.pdf") );
    QVERIFY( doc );
    QVERIFY( doc->isLocked() );
    QVERIFY( !doc->unlock( "", "password" ) );
    QVERIFY( !doc->isLocked() );

    delete doc;
}
Exemplo n.º 3
0
void TestPassword::password2b()
{
    Poppler::Document *doc;
    doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf") );
    QVERIFY( doc );
    QVERIFY( !doc->isLocked() );
    QVERIFY( !doc->unlock( QString::fromUtf8("garçon").toLatin1(), "" ) );
    QVERIFY( !doc->isLocked() );

    delete doc;
}
Exemplo n.º 4
0
void PdfViewer::loadDocument(const QString &file, PdfView::PositionHandling keepPosition)
{
//QTime t = QTime::currentTime();
#ifndef QT_NO_CURSOR
	QApplication::setOverrideCursor(Qt::WaitCursor);
#endif // QT_NO_CURSOR

	// TODO: close only when the new file fails to load
	const QString tempFileName = file; // we must copy file in a new variable because otherwise closeDocument() empties file if file == m_file (which is the case in slotReload())
	closeDocument();

	bool isLoaded = m_pdfView->load(tempFileName);
	if (!isLoaded) {
		QPointer<QMessageBox> msgBox = new QMessageBox(QMessageBox::Critical,
		    tr("Open Error"), tr("Cannot open:\n") + tempFileName,
		    QMessageBox::Ok, this);
		msgBox->exec();
		delete msgBox;
		m_fileOpenRecentAction->removeFile(tempFileName);
#ifndef QT_NO_CURSOR
		QApplication::restoreOverrideCursor();
#endif // QT_NO_CURSOR
		return;
	}

	Poppler::Document *doc = m_pdfView->document();
	while (doc->isLocked()) {
		bool ok = true;
		QString password = QInputDialog::getText(this, tr("Document Password"),
		                                         tr("Please insert the password of the document:"),
		                                         QLineEdit::Password, QString(), &ok);
		if (!ok) {
			m_pdfView->close();
			m_fileOpenRecentAction->removeFile(tempFileName);
#ifndef QT_NO_CURSOR
			QApplication::restoreOverrideCursor();
#endif // QT_NO_CURSOR
			return;
		}
		doc->unlock(password.toLatin1(), password.toLatin1());
	}

	m_file = QFileInfo(tempFileName).absoluteFilePath();

	m_fileOpenRecentAction->addFile(m_file);
	// remove previous file from m_watcher and add new file
	if (m_watcher)
	{
		const QStringList files = m_watcher->files();
		if (!files.isEmpty())
			m_watcher->removePaths(files);
		m_watcher->addPath(m_file);
	}

//qCritical() << t.msecsTo(QTime::currentTime());
    Q_FOREACH(DocumentObserver *obs, m_observers) {
		if (keepPosition == PdfView::DontKeepPosition)
			obs->documentLoaded();
        obs->pageChanged(m_currentPage, keepPosition);
//qCritical() << t.msecsTo(QTime::currentTime());
    }

	// set window title
	const QString docTitle = doc->info("Title");
	setWindowTitle((docTitle.isEmpty() ? QFileInfo(m_file).fileName() : docTitle)
	    + " - " + QCoreApplication::applicationName());

	// enable actions
    m_fileSaveCopyAction->setEnabled(true);
	m_findAction->setEnabled(true);
	m_findNextAction->setEnabled(true);
	m_findPreviousAction->setEnabled(true);
	m_showPresentationAction->setEnabled(true);

#ifndef QT_NO_CURSOR
	QApplication::restoreOverrideCursor();
#endif // QT_NO_CURSOR
//qCritical() << "close and load document" << t.msecsTo(QTime::currentTime());
}