diff --git a/core/document.cpp b/core/document.cpp
index 372af56..578234b 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -155,6 +155,9 @@ QString DocumentPrivate::pagesSizeString() const
 
 QString DocumentPrivate::namePaperSize(double inchesWidth, double inchesHeight) const
 {
+    if( m_noUI )
+        return QString();
+   
     // Account for small deviations in paper sizes
     static const double marginFactor = 0.03;
     static const double lowerBoundFactor = 1.0 - marginFactor;
@@ -167,8 +170,8 @@ QString DocumentPrivate::namePaperSize(double inchesWidth, double inchesHeight)
 
     // Use QPrinter to find which of the predefined paper sizes
     // matches best the given paper width and height
-    QPrinter dummyPrinter;
     QPrinter::PaperSize paperSize = QPrinter::Custom;
+    QPrinter dummyPrinter;
     for (int i = 0; i < (int)QPrinter::NPaperSize; ++i)
     {
         const QPrinter::PaperSize ps = (QPrinter::PaperSize)i;
@@ -913,7 +916,8 @@ bool DocumentPrivate::openDocumentInternal( const KService::Ptr& offer, bool iss
     QObject::connect( m_generator, SIGNAL(warning(QString,int)), m_parent, SIGNAL(warning(QString,int)) );
     QObject::connect( m_generator, SIGNAL(notice(QString,int)), m_parent, SIGNAL(notice(QString,int)) );
 
-    QApplication::setOverrideCursor( Qt::WaitCursor );
+    if( !m_noUI )
+        QApplication::setOverrideCursor( Qt::WaitCursor );
     bool openOk = false;
     if ( !isstdin )
     {
@@ -943,7 +947,8 @@ bool DocumentPrivate::openDocumentInternal( const KService::Ptr& offer, bool iss
         }
     }
 
-    QApplication::restoreOverrideCursor();
+    if( !m_noUI )
+        QApplication::restoreOverrideCursor();
     if ( !openOk || m_pagesVector.size() <= 0 )
     {
         if ( !catalogName.isEmpty() )
@@ -1463,7 +1468,8 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
     if ((m_searchCancelled && !searchStruct->match) || !search)
     {
         // if the user cancelled but he just got a match, give him the match!
-        QApplication::restoreOverrideCursor();
+        if( !m_noUI )
+            QApplication::restoreOverrideCursor();
 
         if (search) search->isCurrentlySearching = false;
 
@@ -1527,7 +1533,8 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
 void DocumentPrivate::doProcessSearchMatch( RegularAreaRect *match, RunningSearch *search, QSet< int > *pagesToNotify, int currentPage, int searchID, bool moveViewport, const QColor & color )
 {
     // reset cursor to previous shape
-    QApplication::restoreOverrideCursor();
+    if( !m_noUI )
+        QApplication::restoreOverrideCursor();
 
     bool foundAMatch = false;
 
@@ -1585,7 +1592,8 @@ void DocumentPrivate::doContinueAllDocumentSearch(void *pagesToNotifySet, void *
     {
         typedef QVector<RegularAreaRect *> MatchesVector;
 
-        QApplication::restoreOverrideCursor();
+        if( !m_noUI )
+            QApplication::restoreOverrideCursor();
 
         if (search) search->isCurrentlySearching = false;
 
@@ -1628,7 +1636,8 @@ void DocumentPrivate::doContinueAllDocumentSearch(void *pagesToNotifySet, void *
     else
     {
         // reset cursor to previous shape
-        QApplication::restoreOverrideCursor();
+        if( !m_noUI )
+            QApplication::restoreOverrideCursor();
 
         search->isCurrentlySearching = false;
         bool foundAMatch = pageMatches->count() != 0;
@@ -1674,7 +1683,8 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo
     {
         typedef QVector<MatchColor> MatchesVector;
 
-        QApplication::restoreOverrideCursor();
+        if( !m_noUI )
+            QApplication::restoreOverrideCursor();
 
         if (search) search->isCurrentlySearching = false;
 
@@ -1748,7 +1758,8 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo
     else
     {
         // reset cursor to previous shape
-        QApplication::restoreOverrideCursor();
+        if( !m_noUI )
+            QApplication::restoreOverrideCursor();
 
         search->isCurrentlySearching = false;
         bool foundAMatch = pageMatches->count() != 0;
@@ -1852,6 +1863,7 @@ Document::Document( QWidget *widget )
     : QObject( 0 ), d( new DocumentPrivate( this ) )
 {
     d->m_widget = widget;
+    d->m_noUI = !widget;
     d->m_bookmarkManager = new BookmarkManager( d );
     d->m_viewportIterator = d->m_viewportHistory.insert( d->m_viewportHistory.end(), DocumentViewport() );
 
@@ -3182,7 +3194,8 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q
     s->highlightedPages.clear();
 
     // set hourglass cursor
-    QApplication::setOverrideCursor( Qt::WaitCursor );
+    if( !d->m_noUI )
+        QApplication::setOverrideCursor( Qt::WaitCursor );
 
     // 1. ALLDOC - proces all document marking pages
     if ( type == AllDocument )
diff --git a/core/document_p.h b/core/document_p.h
index 57a3bee..aa1b86c 100644
--- a/core/document_p.h
+++ b/core/document_p.h
@@ -254,6 +254,8 @@ class DocumentPrivate
 
         QSet< View * > m_views;
 
+        bool m_noUI;
+
         bool m_annotationEditingEnabled;
         bool m_annotationsNeedSaveAs;
         bool m_annotationBeingMoved; // is an annotation currently being moved?
