diff --git a/src/PDFDocument.cxx b/src/PDFDocument.cxx
index 6567e9b..f5710e7 100644
--- a/src/PDFDocument.cxx
+++ b/src/PDFDocument.cxx
@@ -19,6 +19,7 @@
 #include <gdk/gdk.h>
 #include <time.h>
 #include <poppler.h>
+#include <poppler/ErrorCodes.h>
 #include <unistd.h>
 #include "epdfview.h"
 
@@ -210,7 +211,7 @@ PDFDocument::loadFile (const gchar *filename, const gchar *password,
         return FALSE;
     }
     // Try to open the PDF document.
-    GError *loadError = NULL;
+
     // In case the user specified to read the PDF file from the stdin
     // (i.e., -), then we save the contents of the stdin to a temporary
     // file and use the URI to this temporary file to load.
@@ -241,38 +242,12 @@ PDFDocument::loadFile (const gchar *filename, const gchar *password,
         }
     }
     PopplerDocument *newDocument =
-        poppler_document_new_from_file (filename_uri, password, &loadError);
+        poppler_document_new_from_file (filename_uri, password, error);
     g_free (filename_uri);
     // Check if the document couldn't be opened successfully and why.
-    if ( NULL == newDocument )
-    {
-        // Poppler's glib wrapper passes the Poppler error code unless the
-        // error is that the file is encrypted. We want to set our own
-        // error code in this case.
-        DocumentError errorCode = DocumentErrorNone;
-        if ( POPPLER_ERROR == loadError->domain )
-        {
-            errorCode = DocumentErrorEncrypted;
-        }
-        else
-        {
-            // OK, the glib's wrapper don't pass the error code directly
-            // from Poppler. Instead returns G_FILE_ERROR_FAILED and a
-            // non translated string.
-            // Maybe I'm wrong (very probable) but that's a wrong way.
-            // So I'm reading the error code from the error string...
-            sscanf (loadError->message, "Failed to load document (error %d)",
-                    (gint *)&errorCode);
-        }
-        g_error_free (loadError);
-        // Get our error message.
-        gchar *errorMessage = IDocument::getErrorMessage (errorCode);
-        g_set_error (error,
-                     EPDFVIEW_DOCUMENT_ERROR, errorCode,
-                     _("Failed to load document '%s'.\n%s\n"),
-                     filename, errorMessage);
-        g_free (errorMessage);
-
+    if ( !newDocument ) {
+        if ( (*error)->code && (*error)->code==POPPLER_ERROR_ENCRYPTED )
+            (*error)->code = DocumentErrorEncrypted;
         return FALSE;
     }
 
