@ -178,10 +178,12 @@ var PDFViewerApplication = {
preferencePdfBugEnabled : false ,
preferencePdfBugEnabled : false ,
preferenceShowPreviousViewOnLoad : true ,
preferenceShowPreviousViewOnLoad : true ,
preferenceDefaultZoomValue : '' ,
preferenceDefaultZoomValue : '' ,
preferenceDisablePageLabels : false ,
isViewerEmbedded : ( window . parent !== window ) ,
isViewerEmbedded : ( window . parent !== window ) ,
url : '' ,
url : '' ,
baseUrl : '' ,
baseUrl : '' ,
externalServices : DefaultExernalServices ,
externalServices : DefaultExernalServices ,
hasPageLabels : false ,
// called once when the document is loaded
// called once when the document is loaded
initialize : function pdfViewInitialize ( appConfig ) {
initialize : function pdfViewInitialize ( appConfig ) {
@ -380,6 +382,9 @@ var PDFViewerApplication = {
// before the various viewer components are initialized.
// before the various viewer components are initialized.
self . pdfViewer . renderInteractiveForms = value ;
self . pdfViewer . renderInteractiveForms = value ;
} ) ,
} ) ,
Preferences . get ( 'disablePageLabels' ) . then ( function resolved ( value ) {
self . preferenceDisablePageLabels = value ;
} ) ,
// TODO move more preferences and other async stuff here
// TODO move more preferences and other async stuff here
] ) . catch ( function ( reason ) { } ) ;
] ) . catch ( function ( reason ) { } ) ;
@ -567,6 +572,7 @@ var PDFViewerApplication = {
}
}
this . store = null ;
this . store = null ;
this . isInitialViewSet = false ;
this . isInitialViewSet = false ;
this . hasPageLabels = false ;
this . pdfSidebar . reset ( ) ;
this . pdfSidebar . reset ( ) ;
this . pdfOutlineViewer . reset ( ) ;
this . pdfOutlineViewer . reset ( ) ;
@ -879,7 +885,8 @@ var PDFViewerApplication = {
this . pageRotation = 0 ;
this . pageRotation = 0 ;
this . pdfThumbnailViewer . setDocument ( pdfDocument ) ;
var pdfThumbnailViewer = this . pdfThumbnailViewer ;
pdfThumbnailViewer . setDocument ( pdfDocument ) ;
firstPagePromise . then ( function ( pdfPage ) {
firstPagePromise . then ( function ( pdfPage ) {
downloadedPromise . then ( function ( ) {
downloadedPromise . then ( function ( ) {
@ -959,6 +966,33 @@ var PDFViewerApplication = {
} ) ;
} ) ;
} ) ;
} ) ;
pdfDocument . getPageLabels ( ) . then ( function ( labels ) {
if ( ! labels || self . preferenceDisablePageLabels ) {
return ;
}
var i = 0 , numLabels = labels . length ;
if ( numLabels !== self . pagesCount ) {
console . error ( 'The number of Page Labels does not match ' +
'the number of pages in the document.' ) ;
return ;
}
// Ignore page labels that correspond to standard page numbering.
while ( i < numLabels && labels [ i ] === ( i + 1 ) . toString ( ) ) {
i ++ ;
}
if ( i === numLabels ) {
return ;
}
pdfViewer . setPageLabels ( labels ) ;
pdfThumbnailViewer . setPageLabels ( labels ) ;
self . hasPageLabels = true ;
self . _updateUIToolbar ( {
resetNumPages : true ,
} ) ;
} ) ;
pagesPromise . then ( function ( ) {
pagesPromise . then ( function ( ) {
if ( self . supportsPrinting ) {
if ( self . supportsPrinting ) {
pdfDocument . getJavaScript ( ) . then ( function ( javaScript ) {
pdfDocument . getJavaScript ( ) . then ( function ( javaScript ) {
@ -1186,6 +1220,7 @@ var PDFViewerApplication = {
/ * *
/ * *
* @ typedef UpdateUIToolbarParameters
* @ typedef UpdateUIToolbarParameters
* @ property { number } pageNumber
* @ property { number } pageNumber
* @ property { string } pageLabel
* @ property { string } scaleValue
* @ property { string } scaleValue
* @ property { number } scale
* @ property { number } scale
* @ property { boolean } resetNumPages
* @ property { boolean } resetNumPages
@ -1226,11 +1261,25 @@ var PDFViewerApplication = {
var pagesCount = this . pagesCount ;
var pagesCount = this . pagesCount ;
if ( resetNumPages ) {
if ( resetNumPages ) {
toolbarConfig . numPages . textContent =
if ( this . hasPageLabels ) {
mozL10n . get ( 'page_of' , { pageCount : pagesCount } , 'of {{pageCount}}' ) ;
toolbarConfig . pageNumber . type = 'text' ;
} else {
toolbarConfig . pageNumber . type = 'number' ;
toolbarConfig . numPages . textContent = mozL10n . get ( 'of_pages' ,
{ pagesCount : pagesCount } , 'of {{pagesCount}}' ) ;
}
toolbarConfig . pageNumber . max = pagesCount ;
toolbarConfig . pageNumber . max = pagesCount ;
}
}
if ( this . hasPageLabels ) {
toolbarConfig . pageNumber . value = params . pageLabel ||
this . pdfViewer . currentPageLabel ;
toolbarConfig . numPages . textContent = mozL10n . get ( 'page_of_pages' ,
{ pageNumber : pageNumber , pagesCount : pagesCount } ,
'({{pageNumber}} of {{pagesCount}})' ) ;
} else {
toolbarConfig . pageNumber . value = pageNumber ;
toolbarConfig . pageNumber . value = pageNumber ;
}
toolbarConfig . previous . disabled = ( pageNumber <= 1 ) ;
toolbarConfig . previous . disabled = ( pageNumber <= 1 ) ;
toolbarConfig . next . disabled = ( pageNumber >= pagesCount ) ;
toolbarConfig . next . disabled = ( pageNumber >= pagesCount ) ;
@ -1495,11 +1544,13 @@ function webViewerInitialized() {
} ) ;
} ) ;
appConfig . toolbar . pageNumber . addEventListener ( 'change' , function ( ) {
appConfig . toolbar . pageNumber . addEventListener ( 'change' , function ( ) {
PDFViewerApplication . page = ( this . value | 0 ) ;
var pdfViewer = PDFViewerApplication . pdfViewer ;
pdfViewer . currentPageLabel = this . value ;
// Ensure that the page number input displays the correct value, even if the
// Ensure that the page number input displays the correct value, even if the
// value entered by the user was invalid (e.g. a floating point number).
// value entered by the user was invalid (e.g. a floating point number).
if ( this . value !== PDFViewerApplication . page . toString ( ) ) {
if ( this . value !== pdfViewer . currentPageNumber . toString ( ) &&
this . value !== pdfViewer . currentPageLabel ) {
PDFViewerApplication . _updateUIToolbar ( { } ) ;
PDFViewerApplication . _updateUIToolbar ( { } ) ;
}
}
} ) ;
} ) ;
@ -1930,6 +1981,7 @@ function webViewerPageChanging(e) {
PDFViewerApplication . _updateUIToolbar ( {
PDFViewerApplication . _updateUIToolbar ( {
pageNumber : page ,
pageNumber : page ,
pageLabel : e . pageLabel ,
} ) ;
} ) ;
if ( PDFViewerApplication . pdfSidebar . isThumbnailViewVisible ) {
if ( PDFViewerApplication . pdfSidebar . isThumbnailViewVisible ) {