PDFDoc() now detects argument type

This commit is contained in:
Artur Adib 2011-09-27 12:57:33 -04:00
parent 6ae80b5e78
commit a4a8126a40

22
pdf.js
View File

@ -172,7 +172,8 @@ var Stream = (function streamStream() {
}, },
makeSubStream: function stream_makeSubstream(start, length, dict) { makeSubStream: function stream_makeSubstream(start, length, dict) {
return new Stream(this.bytes.buffer, start, length, dict); return new Stream(this.bytes.buffer, start, length, dict);
} },
isStream: true
}; };
return constructor; return constructor;
@ -3800,8 +3801,21 @@ var Catalog = (function catalogCatalog() {
})(); })();
var PDFDoc = (function pdfDoc() { var PDFDoc = (function pdfDoc() {
function constructor(data) { function constructor(arg, callback) {
var stream = new Stream(data); // Stream argument
if (typeof arg.isStream !== 'undefined') {
init.call(this, arg);
}
// ArrayBuffer argument
else if (typeof arg.byteLength !== 'undefined') {
init.call(this, new Stream(arg));
}
else {
error('Unknown argument type');
}
}
function init(stream){
assertWellFormed(stream.length > 0, 'stream must have data'); assertWellFormed(stream.length > 0, 'stream must have data');
this.stream = stream; this.stream = stream;
this.setup(); this.setup();
@ -3822,7 +3836,7 @@ var PDFDoc = (function pdfDoc() {
stream.pos += index; stream.pos += index;
return true; /* found */ return true; /* found */
} }
constructor.prototype = { constructor.prototype = {
get linearization() { get linearization() {
var length = this.stream.length; var length = this.stream.length;