From 1f56d242fffeffdb2a892e94e16e36eb2e4e1277 Mon Sep 17 00:00:00 2001
From: Yury Delendik <ydelendik@mozilla.com>
Date: Mon, 5 Nov 2012 11:12:17 -0600
Subject: [PATCH] Adds basic PDF info

---
 src/core.js   | 15 ++++++++++++++-
 web/viewer.js |  5 +++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/core.js b/src/core.js
index b9e472e94..bd9ff7da2 100644
--- a/src/core.js
+++ b/src/core.js
@@ -495,6 +495,17 @@ var PDFDocument = (function PDFDocumentClosure() {
       if (find(stream, '%PDF-', 1024)) {
         // Found the header, trim off any garbage before it.
         stream.moveStart();
+        // Reading file format version
+        var MAX_VERSION_LENGTH = 12;
+        var version = '', ch;
+        while ((ch = stream.getChar()) > ' ') {
+          if (version.length >= MAX_VERSION_LENGTH) {
+            break;
+          }
+          version += ch;
+        }
+        // removing "%PDF-"-prefix
+        this.pdfFormatVersion = version.substring(5);
         return;
       }
       // May not be a PDF file, continue anyway.
@@ -519,7 +530,9 @@ var PDFDocument = (function PDFDocumentClosure() {
       if (this.xref.trailer.has('Info')) {
         var infoDict = this.xref.trailer.get('Info');
 
-        docInfo = {};
+        docInfo = {
+          PDFFormatVersion: this.pdfFormatVersion
+        };
         var validEntries = DocumentInfoValidators.entries;
         // Only fill the document info with valid entries from the spec.
         for (var key in validEntries) {
diff --git a/web/viewer.js b/web/viewer.js
index d69f1f4c7..fcbabd0db 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1277,6 +1277,11 @@ var PDFView = {
       self.documentInfo = info;
       self.metadata = metadata;
 
+      // Provides some basic debug information
+      console.log('PDF ' + pdfDocument.fingerprint + ' [' +
+                  info.PDFFormatVersion + ' ' + (info.Producer || '-') +
+                  ' / ' + (info.Creator || '-') + ']');
+
       var pdfTitle;
       if (metadata) {
         if (metadata.has('dc:title'))