add PDFDoc

This commit is contained in:
Andreas Gal 2011-05-02 15:34:59 -07:00
parent 9334143941
commit 07571b0bbf

51
pdf.js
View File

@ -553,42 +553,47 @@ var Linearization = (function () {
}; };
})(); })();
var linearization; var PDFDoc = (function () {
function getLinearization() { function constructor(arrayBuffer) {
if (linearization) this.setup(arrayBuffer);
}
constructor.prototype = {
getLinearization: function() {
var linearization = this.linearization;
if (!linearization)
return this.linearization = new Linearization(this.stream);
return linearization; return linearization;
return linearization = new Linearization(stream); },
} isLinearized: function() {
var length = this.stream.length;
function isLinearized() { return length && this.getLinearization().length == length;
return stream.length && getLinearization().length == stream.length; },
} // Find the header, remove leading garbage and setup the stream
// starting from the header.
var stream; checkHeader: function(arrayBuffer) {
// Find the header, remove leading garbage and setup the stream
// starting from the header.
function checkHeader(arrayBuffer) {
const headerSearchSize = 1024; const headerSearchSize = 1024;
stream = new Uint8Array(arrayBuffer); var stream = new Uint8Array(arrayBuffer);
var skip = 0; var skip = 0;
var header = "%PDF-"; var header = "%PDF-";
while (skip < headerSearchSize) { while (skip < headerSearchSize) {
for (var i = 0; i < header.length; ++i) for (var i = 0; i < header.length; ++i)
if (stream[skip+i] != header.charCodeAt(i)) if (this.stream[skip+i] != header.charCodeAt(i))
break; break;
// Found the header, trim off any garbage before it. // Found the header, trim off any garbage before it.
if (i == header.length) { if (i == header.length) {
stream = new Uint8Array(arrayBuffer, skip); this.stream = new Uint8Array(arrayBuffer, skip);
return; return;
} }
} }
// May not be a PDF file, continue anyway. // May not be a PDF file, continue anyway.
} this.stream = stream;
},
function setup(arrayBuffer, ownerPassword, userPassword) { setup: function(arrayBuffer, ownerPassword, userPassword) {
var ub = checkHeader(arrayBuffer); this.checkHeader(arrayBuffer);
} }
};
})();