@@ -21,46 +21,47 @@ Check [`bower.json` file](https://github.com/sayanee/angularjs-pdf/blob/master/b
21
21
###Features
22
22
23
23
1 . next / previous page
24
- 1 . zoom in / out
25
- 1 . rotate clockwise
26
- 1 . jump to a page number
27
- 1 . when scrolling, the pdf controls will get fixed position at the top
28
- 1 . define the view template
29
- 1 . define the path to pdf with scope variable
24
+ - zoom in / out
25
+ - rotate clockwise
26
+ - jump to a page number
27
+ - when scrolling, the pdf controls will get fixed position at the top
28
+ - define the view template
29
+ - define the path to pdf with scope variable
30
+ - handles error
30
31
31
32
## Getting Started
32
33
33
34
1 . install or copy over the file ` dist/angular-pdf.min.js ` or ` dist/angular-pdf.js `
34
35
35
- ```
36
+ ``` shell
36
37
bower install angular-pdf
37
38
```
38
39
1. include the path to the direcitve file in ` index.html`
39
40
40
- ```
41
+ ` ` ` html
41
42
< script src=" js/vendor/angular-pdf/dist/angular-pdf.js" ></script>
42
43
` ` `
43
44
44
45
1. include the directive as a dependency when defining the angular app:
45
46
46
- ```
47
+ ` ` ` js
47
48
var app = angular.module(' App' , [' pdf' ]);
48
49
` ` `
49
50
1. include the directive with the attribute path to the partial under a controller
50
51
51
- ```
52
+ ` ` ` html
52
53
< div class=" wrapper" ng-controller=" DocCtrl" >
53
54
< ng-pdf template-url=" /partials/viewer.html" ></ng-pdf>
54
55
< /div>
55
56
` ` `
56
57
1. include the ` canvas` element to display the pdf in the template-url file
57
58
58
- ```
59
+ ` ` ` html
59
60
< canvas id=" pdf-canvas" ></canvas>
60
61
` ` `
61
62
1. include the path to the pdf file in the controller
62
63
63
- ```
64
+ ` ` ` js
64
65
app.controller(' DocCtrl' , function($scope ) {
65
66
$scope .pdfUrl = ' /pdf/relativity.pdf' ;
66
67
});
@@ -82,41 +83,52 @@ Check [`bower.json` file](https://github.com/sayanee/angularjs-pdf/blob/master/b
82
83
` ` `
83
84
1. ** Rotate clockwise** : Include the controls in the view file as defined in the attribute ` template-url` and the initial class ` rotate0`
84
85
85
- ```
86
+ ` ` ` html
86
87
<button ng-click="rotate()">90</span></button>
87
88
...
88
89
<canvas id="pdf-canvas" class="rotate0"></canvas>
89
90
` ` `
90
91
91
92
include the css styles:
92
93
93
- ```
94
+ ` ` ` css
94
95
.rotate0 {-webkit-transform: rotate(0deg); transform: rotate(0deg); }
95
96
.rotate90 {-webkit-transform: rotate(90deg); transform: rotate(90deg); }
96
97
.rotate180 {-webkit-transform: rotate(180deg); transform: rotate(180deg); }
97
98
.rotate270 {-webkit-transform: rotate(270deg); transform: rotate(270deg); }
98
99
` ` `
99
100
1. ** Jump to page number** : Include the controls in the view file as defined in the attribute ` template-url`
100
101
101
- ```
102
+ ` ` ` html
102
103
<span>Page: </span><input type="text" min=1 ng-model="pageNum"><span> / {{pageCount}}</span>
103
104
` ` `
104
105
1. ** Fixed pdf controls upon scrolling** : Wrap the controls in the view file as defined in the attribute ` template-url` with a tag ` nav` with an ` ng-class` . Amend the scroll amount as required.
105
106
106
- ```
107
+ ` ` ` html
107
108
<nav ng-class="{'pdf-controls fixed': scroll > 100, 'pdf-controls': scroll <= 100}">
108
109
...
109
110
</nav>
110
111
` ` `
111
112
112
113
And include the relevant css styles as required:
113
114
114
- ```
115
+ ` ` ` css
115
116
.pdf-controls { width: 100%; display: block; background: #eee; padding: 1em;}
116
117
.fixed { position: fixed; top: 0; left: calc(50% - 480px); z-index: 100; width: 100%; padding: 1em; background: rgba(238, 238, 238,.9); width: 960px; }
117
118
` ` `
118
119
1. open the file ` index.html` with a web server
119
120
121
+ # ##Handle error
122
+
123
+ 1. in the controller, you can call the function `$scope.onError`:
124
+
125
+ ` ` ` js
126
+ $scope .onError = function(error) {
127
+ // handle the error
128
+ // console.log(error);
129
+ }
130
+ ` ` `
131
+
120
132
# #Variations
121
133
122
134
1. If using with [Angular UI modal](http://angular-ui.github.io/bootstrap/# /modal), `pageNum` attribute is no longer required. [Checkout the implementation](https://github.com/sayanee/angularjs-pdf/issues/12)
0 commit comments