you need have node
$ node server.js
In the browser
localhost:8000/demo/index.html
To install with bower
bower install ng-pdfviewer
AngularJS PDF viewer directive using pdf.js.
<button ng-click="prevPage()"><</button>
<button ng-click="nextPage()">></button>
<br>
<span>{{currentPage}}/{{totalPages}}</span>
<br>
<pdfviewer src="test.pdf" on-page-load='pageLoaded(page,total)' id="viewer"></pdfviewer>
and in your AngularJS code:
var app = angular.module('testApp', [ 'ngPDFViewer' ]);
app.controller('TestCtrl', [ '$scope', 'PDFViewerService', function($scope, pdf) {
$scope.viewer = pdf.Instance("viewer");
$scope.nextPage = function() {
$scope.viewer.nextPage();
};
$scope.prevPage = function() {
$scope.viewer.prevPage();
};
$scope.pageLoaded = function(curPage, totalPages) {
$scope.currentPage = curPage;
$scope.totalPages = totalPages;
};
}]);
- AngularJS (http://angularjs.org/)
- PDF.js (http://mozilla.github.io/pdf.js/)
In order to bundle all src/
files into two productions scripts and build the generic
viewer, issue:
$ node make generic
This will generate pdf.js
and pdf.worker.js
in the build/generic/build/
directory.
Both scripts are needed but only pdf.js
needs to be included since pdf.worker.js
will
be loaded by pdf.js
. If you want to support more browsers than Firefox you'll also need
to include compatibility.js
from build/generic/web/
. The PDF.js files are large and
should be minified for production.
Include ng-pdfviewer.js
as JavaScript file, along with pdf.js
and pdf.compat.js
.
Declare ngPDFViewer
as dependency to your module.
You can now use the pdfviewer
tag in your HTML source.
MIT. See LICENSE.md for further details.
Andreas Krennmair [email protected]