]> git.parisson.com Git - pdf.js.git/commitdiff
Added #getFingerprint method to PDFDocModel
authorSaebekassebil <saebekassebil@gmail.com>
Thu, 22 Dec 2011 22:44:42 +0000 (23:44 +0100)
committerSaebekassebil <saebekassebil@gmail.com>
Thu, 22 Dec 2011 22:44:42 +0000 (23:44 +0100)
src/core.js
web/viewer.js

index ac140dafe76afd766e52f8702b46898b4ebfdc77..664ecf33cf3b4cf5db9e219830131432d147dd0a 100644 (file)
@@ -542,6 +542,21 @@ var PDFDocModel = (function PDFDocModelClosure() {
       // shadow the prototype getter
       return shadow(this, 'numPages', num);
     },
+    getFingerprint: function pdfDocGetFingerprint() {
+      if(this.fileID) {
+        return this.fileID;
+      } else {
+        // If we got no fileID, then we generate one, from the first 100 bytes of PDF
+        var data = this.stream.bytes.subarray(0, 100);
+        var hash = calculateMD5(data, 0, data.length);
+        var strHash = '';
+        for(var i = 0, length = hash.length; i < length; i++) {
+          strHash += Number(hash[i]).toString(16);
+        }
+
+        return strHash;
+      }
+    },
     getPage: function pdfDocGetPage(n) {
       return this.catalog.getPage(n);
     }
@@ -568,7 +583,7 @@ var PDFDoc = (function PDFDocClosure() {
     this.data = data;
     this.stream = stream;
     this.pdf = new PDFDocModel(stream);
-    this.fileID = this.pdf.fileID;
+    this.fingerprint = this.pdf.getFingerprint();
     this.catalog = this.pdf.catalog;
     this.objs = new PDFObjects();
 
index 5e8ec773f3aefdb8a1e8d23cf75f918ed23c7d2c..d4afa8faa4ad70c639a8093a1e56061da26b9c35 100644 (file)
@@ -347,7 +347,7 @@ var PDFView = {
       pagesRefMap[pageRef.num + ' ' + pageRef.gen + ' R'] = i;
     }
 
-    var id = pdf.fileID;
+    var id = pdf.fingerprint;
     if (id) {
       var scroll = Settings.get(id + '.scroll', -1);
       if (scroll != -1) {
@@ -895,9 +895,9 @@ function updateViewarea() {
 
 window.addEventListener('scroll', function webViewerScroll(evt) {
   updateViewarea();
-  var fileID;
-  if((fileID = PDFView.pages[0].content.pdf.fileID)) {
-    Settings.set(fileID+'.scroll', window.pageYOffset);
+  var id;
+  if((id = PDFView.pages[0].content.pdf.fingerprint)) {
+    Settings.set(id+'.scroll', window.pageYOffset);
   }
 }, true);