Created
July 1, 2011 05:26
-
-
Save notmasteryet/1057924 to your computer and use it in GitHub Desktop.
Hack for IE to support pdf.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
try { | |
var a = new Uint8Array(1); | |
return; //no need | |
} catch(e) { } | |
function subarray(start, end) { | |
return this.slice(start, end); | |
} | |
function set_(array, offset) { | |
if (arguments.length < 2) offset = 0; | |
for (var i = 0, n = array.length; i < n; ++i, ++offset) | |
this[offset] = array[i] & 0xFF; | |
} | |
// we need typed arrays | |
function TypedArray(arg1) { | |
var result; | |
if (typeof arg1 === "number") { | |
result = new Array(arg1); | |
for (var i = 0; i < arg1; ++i) | |
result[i] = 0; | |
} else | |
result = arg1.slice(0); | |
result.subarray = subarray; | |
result.buffer = result; | |
result.byteLength = result.length; | |
result.set = set_; | |
if (typeof arg1 === "object" && arg1.buffer) | |
result.buffer = arg1.buffer; | |
return result; | |
} | |
window.Uint8Array = TypedArray; | |
window.Uint32Array = TypedArray; | |
window.Int32Array = TypedArray; | |
})(); | |
(function() { | |
if ("response" in XMLHttpRequest.prototype || | |
"mozResponseArrayBuffer" in XMLHttpRequest.prototype || | |
"mozResponse" in XMLHttpRequest.prototype || | |
"responseArrayBuffer" in XMLHttpRequest.prototype) | |
return; | |
Object.defineProperty(XMLHttpRequest.prototype, "response", { | |
get: function() { | |
return new Uint8Array( new VBArray(this.responseBody).toArray() ); | |
} | |
}); | |
})(); | |
(function() { | |
if ("btoa" in window) | |
return; | |
var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
window.btoa = function(chars) { | |
var buffer = ""; | |
var i, n; | |
for (i = 0, n = chars.length; i < n; i += 3) { | |
var b1 = chars.charCodeAt(i) & 0xFF; | |
var b2 = chars.charCodeAt(i + 1) & 0xFF; | |
var b3 = chars.charCodeAt(i + 2) & 0xFF; | |
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4); | |
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64; | |
var d4 = i + 2 < n ? (b3 & 0x3F) : 64; | |
buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4); | |
} | |
return buffer; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, i don't know if somebody is interested but you can open b64 pdf in pdf.js by following this step:
http://stackoverflow.com/questions/11251947/using-pdf-js-to-display-pdf-from-raw-data#
And how to generate Uint8Array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding#Appendix.3A_Decode_a_Base64_string_to_Uint8Array_or_ArrayBuffer