From 1af6732ba939f209660f75a7c6114302737cec70 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 25 Jul 2011 20:39:29 +0200 Subject: [PATCH 1/2] Do not fail on splitted hex string --- pdf.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pdf.js b/pdf.js index 4bed1a851..66d922df2 100644 --- a/pdf.js +++ b/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); } } From f1a8a987573aef9c31ce7691378be63a89a3ee68 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 26 Jul 2011 16:11:09 +0200 Subject: [PATCH 2/2] Make viewer.js compatible with the content type handler addon --- web/viewer.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 0e7cd59db..12a42006f 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -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;