Merge pull request #284 from vingtetun/master
Make viewer.js able to display a pdf on an event
This commit is contained in:
commit
a1cc36fc5d
13
pdf.js
13
pdf.js
@ -2313,11 +2313,16 @@ var Lexer = (function() {
|
||||
}
|
||||
if (specialChars[ch.charCodeAt(0)] != 1) {
|
||||
var x, x2;
|
||||
if (((x = ToHexDigit(ch)) == -1) ||
|
||||
((x2 = ToHexDigit(stream.getChar())) == -1)) {
|
||||
if ((x = ToHexDigit(ch)) == -1)
|
||||
error('Illegal character in hex string');
|
||||
break;
|
||||
}
|
||||
|
||||
ch = stream.getChar();
|
||||
while (specialChars[ch.charCodeAt(0)] == 1)
|
||||
ch = stream.getChar();
|
||||
|
||||
if ((x2 = ToHexDigit(ch)) == -1)
|
||||
error('Illegal character in hex string');
|
||||
|
||||
str += String.fromCharCode((x << 4) | x2);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ function queryParams() {
|
||||
|
||||
function open(url) {
|
||||
document.title = url;
|
||||
if (url.indexOf("http") == 0)
|
||||
return;
|
||||
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url);
|
||||
req.mozResponseType = req.responseType = 'arraybuffer';
|
||||
@ -37,15 +40,23 @@ function open(url) {
|
||||
if (req.readyState == 4 && req.status == req.expected) {
|
||||
var data = (req.mozResponseArrayBuffer || req.mozResponse ||
|
||||
req.responseArrayBuffer || req.response);
|
||||
pdfDocument = new PDFDoc(new Stream(data));
|
||||
numPages = pdfDocument.numPages;
|
||||
document.getElementById('numPages').innerHTML = numPages.toString();
|
||||
goToPage(pageNum);
|
||||
loadDocument(data);
|
||||
}
|
||||
};
|
||||
req.send(null);
|
||||
}
|
||||
|
||||
window.addEventListener("pdfloaded", function(aEvent) {
|
||||
loadDocument(aEvent.detail);
|
||||
}, true);
|
||||
|
||||
function loadDocument(data) {
|
||||
pdfDocument = new PDFDoc(new Stream(data));
|
||||
numPages = pdfDocument.numPages;
|
||||
document.getElementById('numPages').innerHTML = numPages.toString();
|
||||
goToPage(pageNum);
|
||||
}
|
||||
|
||||
function gotoPage(num) {
|
||||
if (0 <= num && num <= numPages)
|
||||
pageNum = num;
|
||||
|
Loading…
Reference in New Issue
Block a user