mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Added #getFingerprint method to PDFDocModel
This commit is contained in:
parent
d44f9f2074
commit
0de0e92bc4
2 changed files with 20 additions and 5 deletions
17
src/core.js
17
src/core.js
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue