From 2094c291698b2745ddab06dc627bb99d05b8ed0e Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Mon, 26 Sep 2011 20:58:18 +0300 Subject: [PATCH] Use data directly in PDFDoc. And create the Stream inside the PDFDoc constructor for a cleaner interface. Also encapsulate unnecessary details from the user. --- pdf.js | 3 ++- test/driver.js | 2 +- web/viewer.js | 2 +- worker/pdf.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pdf.js b/pdf.js index b58cbbc03..449fd9c16 100644 --- a/pdf.js +++ b/pdf.js @@ -3800,7 +3800,8 @@ var Catalog = (function catalogCatalog() { })(); var PDFDoc = (function pdfDoc() { - function constructor(stream) { + function constructor(data) { + var stream = new Stream(data); assertWellFormed(stream.length > 0, 'stream must have data'); this.stream = stream; this.setup(); diff --git a/test/driver.js b/test/driver.js index 8f873fc46..144b97589 100644 --- a/test/driver.js +++ b/test/driver.js @@ -83,7 +83,7 @@ function nextTask() { r.responseArrayBuffer || r.response; try { - task.pdfDoc = new PDFDoc(new Stream(data)); + task.pdfDoc = new PDFDoc(data); } catch (e) { failure = 'load PDF doc : ' + e.toString(); } diff --git a/web/viewer.js b/web/viewer.js index 89d83fe6b..482ac95e0 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -159,7 +159,7 @@ var PDFView = { while (container.hasChildNodes()) container.removeChild(container.lastChild); - var pdf = new PDFDoc(new Stream(data)); + var pdf = new PDFDoc(data); var pagesCount = pdf.numPages; document.getElementById('numPages').innerHTML = pagesCount; diff --git a/worker/pdf.js b/worker/pdf.js index f205547ab..aee0e374d 100644 --- a/worker/pdf.js +++ b/worker/pdf.js @@ -48,7 +48,7 @@ addEventListener('message', function(event) { var data = event.data; // If there is no pdfDocument yet, then the sent data is the PDFDocument. if (!pdfDocument) { - pdfDocument = new PDFDoc(new Stream(data)); + pdfDocument = new PDFDoc(data); postMessage({ action: 'pdf_num_pages', data: pdfDocument.numPages