@@ -224,6 +224,7 @@ var PDFView = {
224
224
thumbnailViewScroll : null ,
225
225
isFullscreen : false ,
226
226
previousScale : null ,
227
+ pageRotation : 0 ,
227
228
228
229
// called once when the document is loaded
229
230
initialize : function pdfViewInitialize () {
@@ -707,6 +708,8 @@ var PDFView = {
707
708
storedHash = 'page=' + page + '&zoom=' + zoom + ',' + left + ',' + top ;
708
709
}
709
710
711
+ this .pageRotation = 0 ;
712
+
710
713
var pages = this .pages = [];
711
714
this .pageText = [];
712
715
this .startedTextExtraction = false ;
@@ -1180,6 +1183,34 @@ var PDFView = {
1180
1183
this .isFullscreen = false ;
1181
1184
this .parseScale (this .previousScale );
1182
1185
this .page = this .page ;
1186
+ },
1187
+
1188
+ rotatePages : function pdfViewPageRotation (delta ) {
1189
+
1190
+ this .pageRotation = (this .pageRotation + 360 + delta ) % 360 ;
1191
+
1192
+ for (var i = 0 , l = this .pages .length ; i < l ; i ++) {
1193
+ var page = this .pages [i ];
1194
+ page .update (page .scale , this .pageRotation );
1195
+ }
1196
+
1197
+ for (var i = 0 , l = this .thumbnails .length ; i < l ; i ++) {
1198
+ var thumb = this .thumbnails [i ];
1199
+ thumb .updateRotation (this .pageRotation );
1200
+ }
1201
+
1202
+ var currentPage = this .pages [this .page - 1 ];
1203
+
1204
+ if (this .isFullscreen ) {
1205
+ this .parseScale ('page-fit' , true );
1206
+ }
1207
+
1208
+ this .renderHighestPriority ();
1209
+
1210
+ // Wait for fullscreen to take effect
1211
+ setTimeout (function () {
1212
+ currentPage .scrollIntoView ();
1213
+ }, 0 );
1183
1214
}
1184
1215
};
1185
1216
@@ -1188,8 +1219,9 @@ var PageView = function pageView(container, pdfPage, id, scale,
1188
1219
this .id = id ;
1189
1220
this .pdfPage = pdfPage ;
1190
1221
1222
+ this .rotation = 0 ;
1191
1223
this .scale = scale || 1.0 ;
1192
- this .viewport = this .pdfPage .getViewport (this .scale );
1224
+ this .viewport = this .pdfPage .getViewport (this .scale , this . pdfPage . rotate );
1193
1225
1194
1226
this .renderingState = RenderingStates .INITIAL ;
1195
1227
this .resume = null ;
@@ -1200,6 +1232,8 @@ var PageView = function pageView(container, pdfPage, id, scale,
1200
1232
var div = this .el = document .createElement ('div' );
1201
1233
div .id = 'pageContainer' + this .id ;
1202
1234
div .className = 'page' ;
1235
+ div .style .width = this .viewport .width + 'px' ;
1236
+ div .style .height = this .viewport .height + 'px' ;
1203
1237
1204
1238
container .appendChild (anchor );
1205
1239
container .appendChild (div );
@@ -1209,12 +1243,18 @@ var PageView = function pageView(container, pdfPage, id, scale,
1209
1243
this .pdfPage .destroy ();
1210
1244
};
1211
1245
1212
- this .update = function pageViewUpdate (scale ) {
1246
+ this .update = function pageViewUpdate (scale , rotation ) {
1213
1247
this .renderingState = RenderingStates .INITIAL ;
1214
1248
this .resume = null ;
1215
1249
1250
+ if (typeof rotation !== 'undefined' ) {
1251
+ this .rotation = rotation ;
1252
+ }
1253
+
1216
1254
this .scale = scale || this .scale ;
1217
- var viewport = this .pdfPage .getViewport (this .scale );
1255
+
1256
+ var totalRotation = (this .rotation + this .pdfPage .rotate ) % 360 ;
1257
+ var viewport = this .pdfPage .getViewport (this .scale , totalRotation );
1218
1258
1219
1259
this .viewport = viewport ;
1220
1260
div .style .width = viewport .width + 'px' ;
@@ -1545,7 +1585,9 @@ var ThumbnailView = function thumbnailView(container, pdfPage, id) {
1545
1585
return false ;
1546
1586
};
1547
1587
1548
- var viewport = pdfPage .getViewport (1 );
1588
+ var rotation = 0 ;
1589
+ var totalRotation = (rotation + pdfPage .rotate ) % 360 ;
1590
+ var viewport = pdfPage .getViewport (1 , totalRotation );
1549
1591
var pageWidth = this .width = viewport .width ;
1550
1592
var pageHeight = this .height = viewport .height ;
1551
1593
var pageRatio = pageWidth / pageHeight ;
@@ -1560,12 +1602,41 @@ var ThumbnailView = function thumbnailView(container, pdfPage, id) {
1560
1602
div .id = 'thumbnailContainer' + id ;
1561
1603
div .className = 'thumbnail' ;
1562
1604
1605
+ var ring = document .createElement ('div' );
1606
+ ring .className = 'thumbnailSelectionRing' ;
1607
+ ring .style .width = canvasWidth + 'px' ;
1608
+ ring .style .height = canvasHeight + 'px' ;
1609
+
1610
+ div .appendChild (ring );
1563
1611
anchor .appendChild (div );
1564
1612
container .appendChild (anchor );
1565
1613
1566
1614
this .hasImage = false ;
1567
1615
this .renderingState = RenderingStates .INITIAL ;
1568
1616
1617
+ this .updateRotation = function (rot ) {
1618
+
1619
+ rotation = rot ;
1620
+ totalRotation = (rotation + pdfPage .rotate ) % 360 ;
1621
+ viewport = pdfPage .getViewport (1 , totalRotation );
1622
+ pageWidth = this .width = viewport .width ;
1623
+ pageHeight = this .height = viewport .height ;
1624
+ pageRatio = pageWidth / pageHeight ;
1625
+
1626
+ canvasHeight = canvasWidth / this .width * this .height ;
1627
+ scaleX = this .scaleX = (canvasWidth / pageWidth );
1628
+ scaleY = this .scaleY = (canvasHeight / pageHeight );
1629
+
1630
+ div .removeAttribute ('data-loaded' );
1631
+ ring .textContent = '';
1632
+ ring .style .width = canvasWidth + 'px' ;
1633
+ ring .style .height = canvasHeight + 'px' ;
1634
+
1635
+ this .hasImage = false ;
1636
+ this .renderingState = RenderingStates .INITIAL ;
1637
+ this .resume = null ;
1638
+ }
1639
+
1569
1640
function getPageDrawContext () {
1570
1641
var canvas = document .createElement ('canvas' );
1571
1642
canvas .id = 'thumbnail' + id ;
@@ -1579,10 +1650,7 @@ var ThumbnailView = function thumbnailView(container, pdfPage, id) {
1579
1650
1580
1651
div .setAttribute ('data-loaded' , true );
1581
1652
1582
- var ring = document .createElement ('div' );
1583
- ring .className = 'thumbnailSelectionRing' ;
1584
1653
ring .appendChild (canvas );
1585
- div .appendChild (ring );
1586
1654
1587
1655
var ctx = canvas .getContext ('2d' );
1588
1656
ctx .save ();
@@ -1608,7 +1676,7 @@ var ThumbnailView = function thumbnailView(container, pdfPage, id) {
1608
1676
1609
1677
var self = this ;
1610
1678
var ctx = getPageDrawContext ();
1611
- var drawViewport = pdfPage .getViewport (scaleX );
1679
+ var drawViewport = pdfPage .getViewport (scaleX , totalRotation );
1612
1680
var renderContext = {
1613
1681
canvasContext : ctx ,
1614
1682
viewport : drawViewport ,
@@ -2016,6 +2084,15 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
2016
2084
PDFView .parseScale (this .value );
2017
2085
});
2018
2086
2087
+ document .getElementById ('page_rotate_ccw' ).addEventListener ('click' ,
2088
+ function () {
2089
+ PDFView .rotatePages (-90 );
2090
+ });
2091
+
2092
+ document .getElementById ('page_rotate_cw' ).addEventListener ('click' ,
2093
+ function () {
2094
+ PDFView .rotatePages (90 );
2095
+ });
2019
2096
2020
2097
//#if (FIREFOX || MOZCENTRAL)
2021
2098
//if (FirefoxCom.requestSync('getLoadingType') == 'passive') {
@@ -2268,6 +2345,18 @@ window.addEventListener('keydown', function keydown(evt) {
2268
2345
handled = true ;
2269
2346
}
2270
2347
break ;
2348
+
2349
+ case 82 : // 'r'
2350
+ PDFView .rotatePages (90 );
2351
+ break ;
2352
+ }
2353
+ }
2354
+
2355
+ if (cmd == 4 ) { // shift-key
2356
+ switch (evt .keyCode ) {
2357
+ case 82 : // 'r'
2358
+ PDFView .rotatePages (-90 );
2359
+ break ;
2271
2360
}
2272
2361
}
2273
2362
0 commit comments