And create the Stream inside the PDFDoc constructor for a cleaner interface.
Also encapsulate unnecessary details from the user.
})();
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();
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();
}
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;
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