Skip to content

Commit

Permalink
loading PDFs dynamically
Browse files Browse the repository at this point in the history
change to allow PDFs to be loaded dynamically
  • Loading branch information
Nivaldo Fernandes authored and Nivaldo Fernandes committed Jul 17, 2015
1 parent 4d2c287 commit 7688504
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions example/js/directives/angular-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,30 @@
}
};

PDFJS.getDocument(url, null, null, scope.onProgress).then(
function(_pdfDoc) {
if (typeof scope.onLoad === 'function' ) {
scope.onLoad();
}

pdfDoc = _pdfDoc;
scope.renderPage(scope.pageToDisplay);

scope.$apply(function() {
scope.pageCount = _pdfDoc.numPages;
});
}, function(error) {
if (error) {
if (typeof scope.onError === 'function') {
scope.onError(error);
}
}
function renderPDF(){
if(url && url.length){
PDFJS.getDocument(url, null, null, scope.onProgress).then(
function(_pdfDoc) {
if (typeof scope.onLoad === 'function' ) {
scope.onLoad();
}

pdfDoc = _pdfDoc;
scope.renderPage(scope.pageToDisplay);

scope.$apply(function() {
scope.pageCount = _pdfDoc.numPages;
});
}, function(error) {
if (error) {
if (typeof scope.onError === 'function') {
scope.onError(error);
}
}
}
);
}
);
}

scope.$watch('pageNum', function(newVal) {
scope.pageToDisplay = parseInt(newVal);
Expand All @@ -130,6 +134,15 @@
}
});

scope.$watch('pdfUrl', function(newVal) {
if(newVal !== ""){
console.log("pdfUrl value change detected: ", scope.pdfUrl);
url = newVal;
scope.pageToDisplay = 1;
renderPDF();
}
});

}
};
} ]);
Expand Down

0 comments on commit 7688504

Please sign in to comment.