@@ -190,6 +190,7 @@ const PDFViewerApplication = {
190190 _caretBrowsing : null ,
191191 _isScrolling : false ,
192192 editorUndoBar : null ,
193+ _printPermissionPromise : null ,
193194
194195 // Called once when the document is loaded.
195196 async initialize ( appConfig ) {
@@ -369,6 +370,7 @@ const PDFViewerApplication = {
369370 enableAutoLinking : x => x === "true" ,
370371 enableFakeMLManager : x => x === "true" ,
371372 enableGuessAltText : x => x === "true" ,
373+ enablePermissions : x => x === "true" ,
372374 enableUpdatedAddImage : x => x === "true" ,
373375 highlightEditorColors : x => x ,
374376 maxCanvasPixels : x => parseInt ( x ) ,
@@ -407,6 +409,7 @@ const PDFViewerApplication = {
407409 )
408410 : new EventBus ( ) ;
409411 this . eventBus = AppOptions . eventBus = eventBus ;
412+
410413 mlManager ?. setEventBus ( eventBus , abortSignal ) ;
411414
412415 const overlayManager = ( this . overlayManager = new OverlayManager ( ) ) ;
@@ -798,9 +801,19 @@ const PDFViewerApplication = {
798801 } ) ;
799802 }
800803
804+ const togglePrintingButtons = visible => {
805+ appConfig . toolbar ?. print ?. classList . toggle ( "hidden" , ! visible ) ;
806+ appConfig . secondaryToolbar ?. printButton . classList . toggle (
807+ "hidden" ,
808+ ! visible
809+ ) ;
810+ } ;
801811 if ( ! this . supportsPrinting ) {
802- appConfig . toolbar ?. print ?. classList . add ( "hidden" ) ;
803- appConfig . secondaryToolbar ?. printButton . classList . add ( "hidden" ) ;
812+ togglePrintingButtons ( false ) ;
813+ } else {
814+ eventBus . on ( "printingallowed" , ( { isAllowed } ) =>
815+ togglePrintingButtons ( isAllowed )
816+ ) ;
804817 }
805818
806819 if ( ! this . supportsFullscreen ) {
@@ -1335,6 +1348,25 @@ const PDFViewerApplication = {
13351348 load ( pdfDocument ) {
13361349 this . pdfDocument = pdfDocument ;
13371350
1351+ this . _printPermissionPromise = new Promise ( resolve => {
1352+ this . eventBus . on (
1353+ "printingallowed" ,
1354+ ( { isAllowed } ) => {
1355+ if (
1356+ typeof PDFJSDev !== "undefined" &&
1357+ PDFJSDev . test ( "MOZCENTRAL" ) &&
1358+ ! isAllowed
1359+ ) {
1360+ window . print = ( ) => {
1361+ console . warn ( "Printing is not allowed." ) ;
1362+ } ;
1363+ }
1364+ resolve ( isAllowed ) ;
1365+ } ,
1366+ { once : true }
1367+ ) ;
1368+ } ) ;
1369+
13381370 pdfDocument . getDownloadInfo ( ) . then ( ( { length } ) => {
13391371 this . _contentLength = length ; // Ensure that the correct length is used.
13401372 this . loadingBar ?. hide ( ) ;
@@ -1893,7 +1925,7 @@ const PDFViewerApplication = {
18931925 return ;
18941926 }
18951927
1896- if ( ! this . supportsPrinting ) {
1928+ if ( ! this . supportsPrinting || ! this . pdfViewer . printingAllowed ) {
18971929 this . _otherError ( "pdfjs-printing-not-supported" ) ;
18981930 return ;
18991931 }
@@ -1961,8 +1993,8 @@ const PDFViewerApplication = {
19611993 this . pdfPresentationMode ?. request ( ) ;
19621994 } ,
19631995
1964- triggerPrinting ( ) {
1965- if ( this . supportsPrinting ) {
1996+ async triggerPrinting ( ) {
1997+ if ( this . supportsPrinting && ( await this . _printPermissionPromise ) ) {
19661998 window . print ( ) ;
19671999 }
19682000 } ,
0 commit comments