Fix EOF checking
diff --git a/ChangeLog b/ChangeLog
index 35d04fd..be8f093 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-08-08  Albert Astals Cid  <aacid@kde.org>
+
+	* poppler/PDFDoc.cc: Improve the checking for %%EOF
+
 2005-08-06  Kristian Høgsberg  <krh@redhat.com>
 
 	* glib/poppler-page.cc:
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 129695a..750a5ec 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -189,7 +189,15 @@
     eof[i] = ch;
   }
   eof[i] = '\0';
-  if (strstr(eof, "%%EOF") == NULL)
+
+  bool found = false;
+  for (i = i - 5; i >= 0; i--) {
+    if (strncmp (&eof[i], "%%EOF", 5) == 0) {
+      found = true;
+      break;
+    }
+  }
+  if (!found)
   {
     error(-1, "Document has not the mandatory ending %%EOF");
     errCode = errDamaged;