Browse Source

Simplify get fingerprint() method

Jakob Miland 12 years ago
parent
commit
c341dd57e5
  1. 22
      src/core/core.js

22
src/core/core.js

@ -17,7 +17,7 @@
/* globals assertWellFormed, calculateMD5, Catalog, error, info, isArray, /* globals assertWellFormed, calculateMD5, Catalog, error, info, isArray,
isArrayBuffer, isName, isStream, isString, Lexer, isArrayBuffer, isName, isStream, isString, Lexer,
Linearization, NullStream, PartialEvaluator, shadow, Stream, Linearization, NullStream, PartialEvaluator, shadow, Stream,
StreamsSequenceStream, stringToPDFString, Util, XRef, StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef,
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
*/ */
@ -481,22 +481,16 @@ var PDFDocument = (function PDFDocumentClosure() {
return shadow(this, 'documentInfo', docInfo); return shadow(this, 'documentInfo', docInfo);
}, },
get fingerprint() { get fingerprint() {
var xref = this.xref, fileID; var xref = this.xref, hash, fileID = '';
if (xref.trailer.has('ID')) { if (xref.trailer.has('ID')) {
fileID = ''; hash = stringToBytes(xref.trailer.get('ID')[0]);
var id = xref.trailer.get('ID')[0];
id.split('').forEach(function(el) {
fileID += Number(el.charCodeAt(0)).toString(16);
});
} else { } else {
// If we got no fileID, then we generate one, hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
// from the first 100 bytes of PDF
var data = this.stream.bytes.subarray(0, 100);
var hash = calculateMD5(data, 0, data.length);
fileID = '';
for (var i = 0, length = hash.length; i < length; i++) {
fileID += Number(hash[i]).toString(16);
} }
for (var i = 0, n = hash.length; i < n; i++) {
fileID += hash[i].toString(16);
} }
return shadow(this, 'fingerprint', fileID); return shadow(this, 'fingerprint', fileID);

Loading…
Cancel
Save